Results 1 to 4 of 4

Thread: Excel export to XML

  1. #1
    Join Date
    Feb 2005

    Excel export to XML


    Im having problems with dates when exporting an excel spreadsheet as an XML file. I have applied an XML map to the spreadsheet in which the users enter data. They then save the spreadsheet as an xml document. Everything exports fine apart from the dates which are appearing as the XLS serial date format (a number). If I format all date fields as text then the data exports fine. The prob Im having is that the users are copying these dates from another spreadsheet where the fields are formatted as dates. When they copy into my spreadsheet it is defaulting my text field back to a date field and thus the dates are saving again as the serial date format. Is there a way tp get the XML file to save whats in the field as when I save as a CSV that date appears fine even though it is formatted as a date field.

  2. #2
    Join Date
    Nov 2002
    Baltimore, Maryland
    Welcome to the wonder that is Excel. I think that the only way to solve this is to use a different method of exporting the data. I would run a little JScript or VB script using the Windows Scripting Host. Or if you or your users are freaked out by the command line then I would write a little HTA that reads the Excel file and generates the XML.
    “The power of the Web is in its universality. Access by everyone regardless of disability is an essential aspect.”
    —Tim Berners-Lee, W3C Director and inventor of the World Wide Web

  3. #3
    Join Date
    Jan 2005
    San Diego, CA
    Excel probably has some settings somewhere for this type of thing which can control the data formats of the export. I don't play around with Excel exports much. Here are some workarounds: (Note that I haven't tested any of these)

    Export it as a CSV initially so the export contains the right data (since you said exporting as a CSV doesn't corrupt the format of the cells).
    Then import it and export it again but this time change the file type to XML.

    Another method:
    Export the orginal as an XML and a CSV.
    Reopen both in seperate sheets, and pick and choose to merge the two as you see fit to a 3rd sheet and finally export as XML.

    On the original, manually change the fields from a date format to a text format before exporting.

    Edit the exported XML file manually and change the fields to your liking from notepad and resave.

    Don't trust the user's input, and have them copy-paste to a different sheet where they can paste in date format.
    Then have another row reference it but this time convert it to the text format.

    Write a note on the excel page adjacent to the cells telling the user to make sure the cells are kept in the text format "@".

    Write a new VBA module using the OnEntry event handler:
    Sub Auto_Open()
              Worksheets("Sheet1").OnEntry = "Test"
    End Sub
    Sub Test()
              MsgBox "A key was pressed."
    End Sub
    That way the subroutine "Test" would be called any time a field in the entire sheet changes.
    Then instead of showing a dialog, for the subroutine, apply a function to make sure a cell range is the proper type:
    Sub Auto_Open()
              Worksheets("Sheet1").OnEntry = "EntryCallBack"
    End Sub
    Sub EntryCallBack()
    	Selection.NumberFormat = "@"
    	'Sets the format to Text for the given range.
    End Sub

    A few links that might come in handy:

    You could also go with Charles' idea and setup a .WSH, .VBS, .JS or .HTA file to open the excel file
    by creating an "Excel.Application" object.
    Make some edits to the page programmatically then SaveAsXMLData().
    Last edited by Ultimater; 01-13-2011 at 05:26 AM.

  4. #4
    Join Date
    Nov 2002
    Baltimore, Maryland
    Quote Originally Posted by Ultimater View Post
    Make some edits to the page programmatically then SaveAsXMLData().
    Actually, my idea is to have the script pull the information from Excel, build the XML tree with the MSXML parser and then save. The idea is to get Excel out of the equation as much as possible.

    Just one caveat. You can read an Excel file with ActiveX and with the Jet engine. The Active X method is way powerful, you can make SQL calls to your sheet, but with Excel it drops data in certain situations. For this use the ActiveX method.
    excel = new ActiveXObject ('Excel.Application');
    book = excel.workbooks.open (fileName);
    sheet = book.worksheets (1);
    headings = [];
    for (i = 1; i <= sheet.usedRange.columns.count; i++) headings.push (sheet.cells (1, i));
    data = array[];
    for (j = 2; j <= sheet.usedRange.rows.count; j++) {
        a = [];
        for (i = 1; i <= sheet.usedRange.columns.count; i++) headings.push (sheet.cells (j, i));
        data.push (a);
    “The power of the Web is in its universality. Access by everyone regardless of disability is an essential aspect.”
    —Tim Berners-Lee, W3C Director and inventor of the World Wide Web

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center



X vBulletin 4.2.2 Debug Information

  • Page Generation 0.32089 seconds
  • Memory Usage 2,872KB
  • Queries Executed 13 (?)
More Information
Template Usage (34):
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_global_above_footer
  • (1)ad_global_below_navbar
  • (1)ad_global_header1
  • (1)ad_global_header2
  • (1)ad_navbar_below
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (1)ad_thread_first_post_content
  • (1)ad_thread_last_post_content
  • (3)bbcode_code
  • (1)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)headinclude_bottom
  • (4)memberaction_dropdown
  • (1)navbar
  • (4)navbar_link
  • (1)navbar_moderation
  • (1)navbar_noticebit
  • (1)navbar_tabs
  • (2)option
  • (4)postbit
  • (4)postbit_onlinestatus
  • (4)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available (6):
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files (26):
  • ./showthread.php
  • ./global.php
  • ./includes/class_bootstrap.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/functions_navigation.php
  • ./includes/class_friendly_url.php
  • ./includes/class_hook.php
  • ./includes/class_bootstrap_framework.php
  • ./vb/vb.php
  • ./vb/phrase.php
  • ./includes/functions_facebook.php
  • ./includes/functions_calendar.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_notice.php
  • ./packages/vbattach/attach.php
  • ./vb/types.php
  • ./vb/cache.php
  • ./vb/cache/db.php
  • ./vb/cache/observer/db.php
  • ./vb/cache/observer.php 

Hooks Called (70):
  • init_startup
  • friendlyurl_resolve_class
  • init_startup_session_setup_start
  • database_pre_fetch_array
  • database_post_fetch_array
  • init_startup_session_setup_complete
  • global_bootstrap_init_start
  • global_bootstrap_init_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • load_show_variables
  • load_forum_show_variables
  • global_state_check
  • global_bootstrap_complete
  • global_start
  • style_fetch
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • strip_bbcode
  • friendlyurl_clean_fragment
  • friendlyurl_geturl
  • forumjump
  • cache_templates
  • cache_templates_process
  • template_register_var
  • template_render_output
  • fetch_template_start
  • fetch_template_complete
  • parse_templates
  • fetch_musername
  • notices_check_start
  • notices_noticebit
  • process_templates_complete
  • friendlyurl_redirect_canonical
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • memberaction_dropdown
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • build_navigation_data
  • build_navigation_array
  • check_navigation_permission
  • process_navigation_links_start
  • process_navigation_links_complete
  • set_navigation_menu_element
  • build_navigation_menudata
  • build_navigation_listdata
  • build_navigation_list
  • set_navigation_tab_main
  • set_navigation_tab_fallback
  • navigation_tab_complete
  • fb_like_button
  • showthread_complete
  • page_templates