/* xls2xml: Converts from Microsoft Excel files to XML. Copyright 1999 Roberto Arturo Tena Sanchez This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ /* Roberto Arturo Tena Sanchez */ #include #include #include #include #include #include #include #include static int process_main_stream (void); static int process_record (void); magic_parameters * parameters; magic_parameters pparameters; /* 5 10 11 15 17 18 19 */ int xls2xml (COLEFILE *colefile, xmlDocPtr * p_xml_doc, int extract_level, int refmode) { U32 main_stream; pparameters.xlsfile = colefile; pparameters.p_xml_doc = p_xml_doc; pparameters.options.extract_level = extract_level; pparameters.options.refmode = refmode; pparameters.dont_care_end = 1; pparameters.jump_to_next_substream = 1; pparameters.biff_version = 0; pparameters.datesystem1904 = 0; pparameters.next_font_refnum = 0; pparameters.next_sheet_refnum = 0; pparameters.this_sheet = NULL; pparameters.this_cells = NULL; pparameters.this_refmode = refmode; pparameters.code_page = 1252; /* CP1252 (ANSI) code page is the MS default (I think) */ pparameters.sst.count = 0; pparameters.sst.strings = NULL; pparameters.xml_tree_shortcuts.first_sheet = pparameters.xml_tree_shortcuts.window_state = pparameters.xml_tree_shortcuts.sheets = pparameters.xml_tree_shortcuts.fonts = pparameters.xml_tree_shortcuts.tabs_state = pparameters.xml_tree_shortcuts.ui = pparameters.xml_tree_shortcuts.defaults = pparameters.xml_tree_shortcuts.code_page = NULL; /* pparameters.associate_offsets_and_sheets = NULL; */ parameters = &pparameters; return process_main_stream (); } /* 5 10 11 15 17 18 19 */ int process_main_stream (void) { int result; /* create xml file */ test_call (new_xml_doc (), int); /* process each record of main stream */ parameters->dont_care_end = 0; parameters->jump_to_next_substream = 0; while ( !(result = get_next_record (parameters->xlsfile)) ) { #ifdef XLS2XML_VERBOSE { record_brdb * r; r = (record_brdb *)bsearch (¶meters->record, brdb, size_brdb, size_record_brdb, &cmp_record_brdb); if (r == NULL) printf ("(0x%08lx) record 0x%04x, size 0x%04x\n", cole_ftell (parameters->xlsfile) - parameters->record.size - 4, parameters->record.opcode, parameters->record.size); else printf ("(0x%08lx) record 0x%04x, size 0x%04x\n(%s, %s)\n", cole_ftell (parameters->xlsfile) - parameters->record.size - 4, parameters->record.opcode, parameters->record.size, r->name, r->desc); verboseU8Array_force (parameters->record.info, 1, parameters->record.size); } #endif /* XLS2XML_VERBOSE */ if (parameters->jump_to_next_substream && parameters->record.opcode != 0x809) continue; test_call_exitf (process_record (), int, { erase_xml_doc (parameters->xml_doc); }); } /* this is called only if get_next_record sends a no zero */ if (result == 14) /* 14 = no more records */ result = 0; /* we've done all ok */ else erase_xml_doc (parameters->xml_doc); return result; } /* 10 15 17 18 19 */ int process_record (void) { record_brdb * r; r = (record_brdb *)bsearch (¶meters->record, brdb, size_brdb, size_record_brdb, &cmp_record_brdb); test (r != NULL, 0); test (r->f != NULL, 0); parameters->record.brdb_entry = r - brdb; if (brdb[parameters->record.brdb_entry].fixed_size && brdb[parameters->record.brdb_entry].fixed_size != parameters->record.size) fprintf (stderr, "xls2xml: Warning: size of record %s doesn't match", brdb[parameters->record.brdb_entry].name); /* call the function that process this record */ return r->f (); }