<< Masa.20101206-update-outline-spreadsheet | 2010 | Masa.20101202-update-outline-sreadsheet >>
masa@masa ~/ywesee/spreadsheet $ cat test.rb require 'spreadsheet' book = Spreadsheet::Workbook.new sheet = book.create_worksheet sheet.column(1).hidden = true sheet.column(2).hidden = true book.write 'out.xls'
Result
BraSt
Experiment
lib/spreadsheet/excel/reader.rb#read_colinfo
def read_colinfo worksheet, work, pos, len p "getin read_colinfo"
test.rb
require 'spreadsheet' file = ARGV[0] book = Spreadsheet.open(file, 'rb') sheet= book.worksheet(0) 5.times {|i| sheet[0,i] = i} book.write "out.xls"
Result
masa@masa ~/ywesee/spreadsheet $ ruby -I lib test.rb test1.xls masa@masa ~/ywesee/spreadsheet $ ruby -I lib test.rb test2.xls "getin read_colinfo" masa@masa ~/ywesee/spreadsheet $ ruby -I lib test.rb test3.xls "getin read_colinfo" masa@masa ~/ywesee/spreadsheet $ ruby -I lib test.rb test4.xls "getin read_colinfo" "getin read_colinfo" masa@masa ~/ywesee/spreadsheet $ ruby -I lib test.rb test5.xls "getin read_colinfo" "getin read_colinfo" "getin read_colinfo"
Notes
Experiment (Rename files)
lib/spreadsheet/excel/reader.rb#read_colinfo
def read_colinfo worksheet, work, pos, len # Offset Size Contents # 0 2 Index to first column in the range # 2 2 Index to last column in the range # 4 2 Width of the columns in 1/256 of the width of the zero # character, using default font (first FONT record in the # file) # 6 2 Index to XF record (➜ 6.115) for default column formatting # 8 2 Option flags: # Bits Mask Contents # 0 0x0001 1 = Columns are hidden # 10-8 0x0700 Outline level of the columns (0 = no outline) # 12 0x1000 1 = Columns are collapsed # 10 2 Not used first, last, width, xf, opts = work.unpack binfmt(:colinfo)[0..-2] print "fitst\tlast\twidth\txf\topts\n" print first,"\t",last,"\t",width,"\t",xf,"\t",opts,"\n\n"
Result
masa@masa ~/ywesee/spreadsheet $ ruby -I lib test.rb hidden.xls fitst last width xf opts 2 3 0 15 3 masa@masa ~/ywesee/spreadsheet $ ruby -I lib test.rb outline.xls fitst last width xf opts 2 3 2925 15 256 masa@masa ~/ywesee/spreadsheet $ ruby -I lib test.rb outline_hidden.xls fitst last width xf opts 2 3 0 15 259 fitst last width xf opts 4 4 2925 15 4096 masa@masa ~/ywesee/spreadsheet $ ruby -I lib test.rb hidden_by_sp.xls fitst last width xf opts 0 1 2560 0 0 fitst last width xf opts 2 3 2560 0 1 fitst last width xf opts 4 4 2560 0 0
Notes
Question
Experiment
lib/spreadsheet/excel/reader.rb#read_colinfo
def read_colinfo worksheet, work, pos, len # Offset Size Contents # 0 2 Index to first column in the range # 2 2 Index to last column in the range # 4 2 Width of the columns in 1/256 of the width of the zero # character, using default font (first FONT record in the # file) # 6 2 Index to XF record (➜ 6.115) for default column formatting # 8 2 Option flags: # Bits Mask Contents # 0 0x0001 1 = Columns are hidden # 10-8 0x0700 Outline level of the columns (0 = no outline) # 12 0x1000 1 = Columns are collapsed # 10 2 Not used first, last, width, xf, opts = work.unpack binfmt(:colinfo)[0..-2] print "fitst\tlast\twidth\txf\topts\n" print first,"\t",last,"\t",width,"\t",xf,"\t",opts,"\n\n" first.upto last do |col| print "col=", col, "\n" print "\twidth=\t\t", width.to_f / 256, "\n" print "\thidden=\t\t", (opts & 0x0001) > 0, "\n" print "\touline_level=\t", (opts & 0x0700), "\n" print "\tcollapsed=\t", (opts & 0x1000) > 0, "\n" column = Column.new col, @workbook.format(xf), :width => width.to_f / 256, :hidden => (opts & 0x0001) > 0, :collapsed => (opts & 0x1000) > 0, :outline_level => (opts & 0x0700) column.worksheet = worksheet worksheet.columns[col] = column end puts end
Result
masa@masa ~/ywesee/spreadsheet $ ruby -I lib test.rb normal.xls masa@masa ~/ywesee/spreadsheet $ ruby -I lib test.rb hidden.xls fitst last width xf opts 2 3 0 15 3 col=2 width= 0.0 hidden= true ouline_level= 0 collapsed= false col=3 width= 0.0 hidden= true ouline_level= 0 collapsed= false masa@masa ~/ywesee/spreadsheet $ ruby -I lib test.rb outline.xls fitst last width xf opts 2 3 2925 15 256 col=2 width= 11.42578125 hidden= false ouline_level= 256 collapsed= false col=3 width= 11.42578125 hidden= false ouline_level= 256 collapsed= false masa@masa ~/ywesee/spreadsheet $ ruby -I lib test.rb outline_hidden.xls fitst last width xf opts 2 3 0 15 259 col=2 width= 0.0 hidden= true ouline_level= 256 collapsed= false col=3 width= 0.0 hidden= true ouline_level= 256 collapsed= false fitst last width xf opts 4 4 2925 15 4096 col=4 width= 11.42578125 hidden= false ouline_level= 0 collapsed= true masa@masa ~/ywesee/spreadsheet $ ruby -I lib test.rb hidden_by_sp.xls fitst last width xf opts 0 1 2560 0 0 col=0 width= 10.0 hidden= false ouline_level= 0 collapsed= false col=1 width= 10.0 hidden= false ouline_level= 0 collapsed= false fitst last width xf opts 2 3 2560 0 1 col=2 width= 10.0 hidden= true ouline_level= 0 collapsed= false col=3 width= 10.0 hidden= true ouline_level= 0 collapsed= false fitst last width xf opts 4 4 2560 0 0 col=4 width= 10.0 hidden= false ouline_level= 0 collapsed= false
Experiment
create_new_file.rb
require 'spreadsheet' book = Spreadsheet::Workbook.new sheet = book.create_worksheet 5.times {|i| sheet[0,i] = i} sheet.column(2).outline_level = 256 sheet.column(3).outline_level = 256 book.write 'out.xls'
Result
masa@masa ~/ywesee/spreadsheet $ ruby -I lib create_new_file.rb masa@masa ~/ywesee/spreadsheet $ vim create_new_file.rb masa@masa ~/ywesee/spreadsheet $ mv out.xls aaa.xls masa@masa ~/ywesee/spreadsheet $ ruby -I lib test.rb aaa.xls fitst last width xf opts 0 1 2560 0 0 col=0 width= 10.0 hidden= false ouline_level= 0 collapsed= false col=1 width= 10.0 hidden= false ouline_level= 0 collapsed= false fitst last width xf opts 2 3 2560 0 0 col=2 width= 10.0 hidden= false ouline_level= 0 collapsed= false col=3 width= 10.0 hidden= false ouline_level= 0 collapsed= false fitst last width xf opts 4 4 2560 0 0 col=4 width= 10.0 hidden= false ouline_level= 0 collapsed= false
Notes
Experiment
lib/spreadsheet/excel/writer/worksheet.rb
def write_colinfo bunch col = bunch.first print "col.idx=", col.idx, "\n" print "col.hidden?=", col.hidden?, "\n" print "col.outline_level=", col.outline_level, "\n" ...
create_new_file.rb
require 'spreadsheet' book = Spreadsheet::Workbook.new sheet = book.create_worksheet 5.times {|i| sheet[0,i] = i} #sheet.column(2).hidden = true sheet.column(2).outline_level = 256 #sheet.column(3).hidden = true sheet.column(3).outline_level = 256 book.write 'out.xls'
Result
masa@masa ~/ywesee/spreadsheet $ ruby -I lib create_new_file.rb col.idx=0 col.hidden?=false col.outline_level=0 col.idx=2 col.hidden?=false col.outline_level=256 col.idx=4 col.hidden?=false col.outline_level=0
Notes
Next
lib/spreadsheet/excel/writer/worksheet.rb
def write_colinfo bunch col = bunch.first print "col.idx=", col.idx, "\n" print "col.hidden?=", col.hidden?, "\n" print "col.outline_level=", col.outline_level, "\n" print "col.collapsed?=", col.collapsed?, "\n" width = col.width.to_f * 256 xf_idx = @workbook.xf_index @worksheet.workbook, col.default_format opts = 0 opts |= 0x0001 if col.hidden? opts |= col.outline_level.to_i << 8 opts |= 0x1000 if col.collapsed? print "opts=", opts, "\n" ...
Result
masa@masa ~/ywesee/spreadsheet $ ruby -I lib create_new_file.rb col.idx=0 col.hidden?=false col.outline_level=0 col.collapsed?=false opts=0 col.idx=2 col.hidden?=false col.outline_level=256 col.collapsed?=false opts=65536 col.idx=4 col.hidden?=false col.outline_level=0 col.collapsed?=false opts=0
Note
Experiment (create a new file forcedly with the same setting of outlined xls file)
lib/spreadsheet/excel/writer/worksheet.rb
def write_colinfo bunch col = bunch.first print "col.idx=", col.idx, "\n" print "col.hidden?=", col.hidden?, "\n" print "col.outline_level=", col.outline_level, "\n" print "col.collapsed?=", col.collapsed?, "\n" width = col.width.to_f * 256 xf_idx = @workbook.xf_index @worksheet.workbook, col.default_format opts = 0 opts |= 0x0001 if col.hidden? opts |= col.outline_level.to_i << 8 opts |= 0x1000 if col.collapsed? print "opts=", opts, "\n" if col.idx == 2 opts = 256 end xf_idx = 15
Run create
masa@masa ~/ywesee/spreadsheet $ ruby -I lib create_new_file.rb
Result
masa@masa ~/ywesee/spreadsheet $ ruby -I lib test.rb aaa.xls fitst last width xf opts 0 1 2560 15 0 col=0 width= 10.0 hidden= false ouline_level= 0 collapsed= false col=1 width= 10.0 hidden= false ouline_level= 0 collapsed= false fitst last width xf opts 2 3 2560 15 256 col=2 width= 10.0 hidden= false ouline_level= 256 collapsed= false col=3 width= 10.0 hidden= false ouline_level= 256 collapsed= false fitst last width xf opts 4 4 2560 15 0 col=4 width= 10.0 hidden= false ouline_level= 0 collapsed= false
Notes
My guess
Check file sizes
masa@masa ~/ywesee/spreadsheet $ ls -la|grep xls -rwxr--r-- 1 masa masa 23552 3. Dez 08:40 hidden.xls -rwxr--r-- 1 masa masa 23040 3. Dez 08:40 normal.xls -rwxr--r-- 1 masa masa 23552 3. Dez 08:40 outline_hidden.xls -rw-r--r-- 1 masa masa 23552 3. Dez 08:40 outline.xls
Notes
Consideration
BraSt
Link http://b2xtranslator.sourceforge.net/download.html
Create Biff data for each file
Diff
Notes
hidden.xls: BIFF GUTS (80h) 8 00 00 00 00 00 00 00 00 outline.xls: BIFF GUTS (80h) 8 00 00 1D 00 00 00 02 00
hidden.xls: BIFF COLINFO (7Dh) 12 02 00 03 00 00 00 0F 00 03 00 00 00 outline.xls: BIFF COLINFO (7Dh) 12 02 00 03 00 6D 0B 0F 00 00 01 00 00
My guess
grep search
masa@masa ~/ywesee/spreadsheet $ grep -r GUTS lib lib/spreadsheet/excel/internals.rb: :guts => 0x0080, # ○ GUTS ➜ 6.49 lib/spreadsheet/excel/writer/worksheet.rb: # ○ GUTS ➜ 5.53
lib/spreadsheet/excel/writer/worksheet.rb#write_from_scratch
def write_from_scratch # ● BOF Type = worksheet (➜ 5.8) write_bof # ○ UNCALCED ➜ 5.105 # ○ INDEX ➜ 4.7 (Row Blocks), ➜ 5.59 # ○ Calculation Settings Block ➜ 4.3 write_calccount write_refmode write_iteration write_saverecalc # ○ PRINTHEADERS ➜ 5.81 # ○ PRINTGRIDLINES ➜ 5.80 # ○ GRIDSET ➜ 5.52 # ○ GUTS ➜ 5.53 # ○ DEFAULTROWHEIGHT ➜ 5.31 write_defaultrowheight # ○ WSBOOL ➜ 5.113 write_wsbool ...
Notes
Next