# Need help adding formatting while using "WriteExcel" for spreadsheet

**URL:** <https://www.ruby-forum.com/t/need-help-adding-formatting-while-using-writeexcel-for-spreadsheet/235480>\
**Category:** Ruby\
**Created:** [June 24, 2013, 7:52pm UTC](https://www.ruby-forum.com/t/need-help-adding-formatting-while-using-writeexcel-for-spreadsheet/235480 "2013-06-24T19:52:25Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![alcina](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/a587f6/32.png) [@alcina](https://www.ruby-forum.com/u/alcina)\
**Post date:** [June 24, 2013, 7:52pm UTC](https://www.ruby-forum.com/t/need-help-adding-formatting-while-using-writeexcel-for-spreadsheet/235480/1 "2013-06-24T19:52:25Z")

</div>

Hello Team,

I am putting together a simple program that basically reads some dated  
data  
and creates a speadsheet. I started using _WriteExcel_ to create the  
spreadsheet and I have couple questions that perhaps someone out there  
can  
help me with.

I am copying the code here but please note that the code ONLY generates  
the  
spreadsheet, I would like to be able to generate the graph also.

I wanted to know:

1. How do I select a different color for the first row, not just for  
a  
single cell?
2. How do I set a larger font for the first row, a different size for  
the third row and “normal” for the rest of the sheet?
3. How can I generate the bar graph that corresponds to the  
spreadsheet,  
like the one shown below, which I manually created?

If someone can point me to some documentation or sample that will be  
great.

Thank you

# ==========================================

require ‘rubygems’  
require ‘writeexcel’  
require ‘pp’

fn = “/home/rb/MyData/lpr\_time.log.\*”

msg\_types = [‘DATE’, ‘read’, “entry”, “delete”, “alarm”, “hotlist”,  
“site”]

fnls = Dir["#{fn}"].sort # Create fnls = file names list in  
chronological order

puts fnls

r = fnls.size # Number of files to be processed = number  
of  
rows  
msg\_count = Array.new(r+1) {Array.new(7) {0}} # r+1 = 1 additional  
row  
for the headings

r = 0; c = 0;  
msg\_types.each do |t|  
msg\_count[r][c] = t.upcase # For spreadsheet heading, make it  
uppercase  
c += 1  
end

# pp msg\_count

r += 1 # Point to row 1  
fnls.each do |f| # Process each file  
lp,lg,dt = f.split(’.’) # Get date part from fn  
6.times do |c| # Process each column  
if c == 0 # When in r=0,c=0 Write date  
fdate = Date.parse(dt).strftime("%a%b%d%Y") # Will go  
from:  
20130611 to 2013-06-11 to TueJun112013  
msg\_count[r][c] = fdate # Write date to column 0  
else  
mtc = `grep -c #{msg_types[c]} #{f}` # Get Message Type  
Count  
msg\_count[r][c] = mtc.to\_i  
end # if  
#pp msg\_count  
end # 6.times  
r += 1  
end # each  
#pp msg\_count

workbook = WriteExcel.new(“lpr\_wb01.xls”)  
worksheet1 = workbook.add\_worksheet(‘Sheet 1’)  
format = workbook.add\_format(:color =\> ‘red’, :bold =\> 1)  
format\_cmd = workbook.add\_format(:color =\> ‘blue’, :bold =\> 1)

worksheet1.write(‘A1’, “WebSphere MQ Weekly Report”, format\_cmd)  
worksheet1.write(‘A3’, [msg\_count], format\_cmd )  
workbook.close

---

<div class="post-metadata">

**Author:** ![rubina](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e47c2d/32.png) [@rubina](https://www.ruby-forum.com/u/rubina)\
**Post date:** [June 25, 2013, 6:30pm UTC](https://www.ruby-forum.com/t/need-help-adding-formatting-while-using-writeexcel-for-spreadsheet/235480/2 "2013-06-25T18:30:50Z")

</div>

Have you looked at this?  
[http://writeexcel.web.fc2.com/en/doc\_en.html#add\_chart](http://writeexcel.web.fc2.com/en/doc_en.html#add_chart)

---

<div class="post-metadata">

**Author:** ![rubina](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e47c2d/32.png) [@rubina](https://www.ruby-forum.com/u/rubina)\
**Post date:** [June 25, 2013, 10:18pm UTC](https://www.ruby-forum.com/t/need-help-adding-formatting-while-using-writeexcel-for-spreadsheet/235480/3 "2013-06-25T22:18:16Z")

</div>

NOPE, but I will right now.

Thank you
