20101207-update-outline-spreadsheet
<< Masa.20101208-update-spreadsheet-gem-debug-ebook | 2010 | Masa.20101206-update-outline-spreadsheet >>
- Check code again and commit
stop commit
- Update write_changes method
- Goal
-
- Update outline spreadsheet / 100%
- Test cases / 70%
- Milestones
-
Check code again 10:00
- Update write_changes
- Test cases
- Summary
-
- Commits
-
- ToDo Tomorrow
-
- Keep in Mind
-
- Author info in code
- VirtualBox kernel module
- todos
- BAG: Files published obviously only on the first ch.ODDB.org Report - Error: Generikaliste - 12/2010 log passwd
- Testcase of 'Object Stream' parser (for rpdf2txt/lib/rpdf2txt/parser.rb#rebuild_object_catalogue method) 20101126-update-rpdf2txt
- Testcases of lib/oddb/html/state/global.rb#grant_download, lib/oddb/html/view/download.rb#to_html
- Debug testcases in test/export/test_server.rb de.oddb.org
- A bug import_gkv Tue Nov 16 02:00:10 2010: de.oddb.org Zubef (PDF)
- Compression (refer to lib/oddb/export/server.rb), Test cases (grant_download, Logging, Reporting)
- Log Error: on production server, de.oddb.org/log/import_dimdi, import_pharmnet
- On Ice
- emerge --sync
Check code again and commit
Problem
- write_from_scratch method is called only in the case of creating a new sheet
- In the case of reading a file, this method is not called
- then write_guts method is not called
Experiment
create_new_file.rb
require 'spreadsheet'
book = Spreadsheet::Workbook.new
sheet = book.create_worksheet
5.times {|j| 5.times {|i| sheet[j,i] = (i+1)*10**j}}
# col
sheet.column(2).hidden = true
sheet.column(2).outline_level = 1
sheet.column(3).hidden = true
sheet.column(3).outline_level = 1
# row
sheet.row(2).hidden = true
sheet.row(2).outline_level = 1
sheet.row(3).hidden = true
sheet.row(3).outline_level = 1
book.write 'out.xls'
Run
masa@masa ~/ywesee/spreadsheet $ ruby -I lib create_new_file.rb
Result
- This works both in Open Office and MS Office
But
edit_little.rb
require 'spreadsheet'
file = ARGV[0]
book = Spreadsheet.open(file, 'rb')
sheet= book.worksheet(0)
5.times {|i| sheet[0,i] = i}
# col
sheet.column(2).hidden = true
sheet.column(3).hidden = true
sheet.column(2).outline_level = 1
sheet.column(3).outline_level = 1
# row
sheet.row(2).hidden = true
sheet.row(3).hidden = true
sheet.row(2).outline_level = 1
sheet.row(3).outline_level = 1
book.write "out.xls"
Run
masa@masa ~/ywesee/spreadsheet $ ruby -I lib edit_little.rb normal.xls
Note
- normal.xls is a xls file made by MS Office without outlines
Result
- On MS Office, this does not work at all
- On Open Office, only row outline works but outline buttons in column is not shown
Notes
- The reason is that write_guts (lib/spreadsheet/excel/write/worksheet.rb) method is not called
- This method is called from write_from_scratch method but this method is only called in the case of creating a new file through spreadsheet
Memo
- There are 3 flows (methods) to write (make) a xls file
- Spreadsheet::Excel::Writer::Workbook#write_from_scratch: creat a new file
- Spreadsheet::Excel::Writer::Workbook#write_chagnes: read and write a file
- Spreadsheet::Write::write_workbook: just copy
- These methods are selected in Spreadsheet::Excel::Writer::Workbook#write_workbook
##
# The main writer method. Calls #write_from_scratch or #write_changes
# depending on the class and state of _workbook_.
def write_workbook workbook, io
unless workbook.is_a?(Excel::Workbook) && workbook.io
@date_base = Date.new 1899, 12, 31
write_from_scratch workbook, io
else
@date_base = workbook.date_base
if workbook.changes.empty?
super
else
write_changes workbook, io
end
end
ensure
cleanup workbook
end
So
- In order to call write_guts method also in the case of reading a file,
- I have to update write_changes method, maybe
Update write_changes method
Memo
- It seems that updating COLINFO and ROW records does not run in the case of updating a file
Check the current functions
Memo
- It is no problem regarding creating a new file
- Just check the updating of a file
Experiment
edit_little.rb
require 'spreadsheet'
file = ARGV[0]
book = Spreadsheet.open(file, 'rb')
sheet= book.worksheet(0)
# col
sheet.column(2).hidden = true
sheet.column(3).hidden = true
sheet.column(2).outline_level = 1
sheet.column(3).outline_level = 1
# row
sheet.row(2).hidden = true
sheet.row(3).hidden = true
sheet.row(2).outline_level = 1
sheet.row(3).outline_level = 1
book.write "out.xls"
Notes
- Reading a file and setting hidden and outline_level properties in rows and columns
Notes
- normal.xls: withouth outlines
- outline_col.xls: with outline in columns
- outline_row.xls: iwth outline in rows
Test1: ruby -I lib edit_littlr.rb normal.xls
Test2: ruby -I lib edit_littlr.rb outline_col.xls
Test3: ruby -I lib edit_littlr.rb outline_row.xls
Notes
- These results indicate that write_colinfo did not run
- These do not work in MS Office at all because write_guts method is not called
- So, write_colinfo and write_guts should run somehow in write_changes method
Focus on Spreadsheet::Excel::Writer::Worksheet#write_changes method
http://scm.ywesee.com/?p=spreadsheet/.git;a=blob;f=lib/spreadsheet/excel/writer/worksheet.rb;h=f48a212c39034101e3283c79682fa3c3c7bbd53e;hb=HEAD#l242
Experiment
lib/spreadsheet/excel/writer/worksheet.rb#write_changes
def write_changes reader, endpos, sst_status
...
work.each do |key, (pos, len)|
@io.write reader.read(pos - lastpos) if pos > lastpos
if key.is_a?(Integer)
if block = blocks.find do |rows| rows.any? do |row| row.idx == key end end
write_rowblock block
blocks.delete block
end
else
send "write_#{key}"
write_colinfos
write_guts
end
lastpos = pos + len
reader.seek lastpos
end
@io.write reader.read(endpos - lastpos)
end
Run
masa@masa ~/ywesee/spreadsheet $ ruby -I lib edit_little.rb normal.xls
masa@masa ~/ywesee/spreadsheet $ ruby -I lib edit_little.rb outline_col.xls
masa@masa ~/ywesee/spreadsheet $ ruby -I lib edit_little.rb outline_row.xls
Result
- Every file has outlines both in row and in column
Notes
- My guess is correct
- Namely, write_guts and write_colinfo are necessary to show outlines
Next
- write_guts and write_colinfo should be called in the case of updating
- otherwise, they should not be called
Commit