Javascript excel to xml

Exporting XML from Excel and Keeping Date Format

Many StackOverflow posts and other online forums have questions similar to this, but none of them really resolve the issue I’m having. I’m exporting an XML file from Excel. The Excel file contains dates. In the XML file, however, those dates show up as integers—the date is made to be the nth day since 1/0/1900, I believe. I’m using JavaScript to extract the data from the XML file to populate a table in a web page. I suspect that a solution could come in two different forms: 1. A way to convert, in JavaScript, the integer to the date it represents. 2. A way to force the XML file to take a formatted date from the Excel file. I’m clearly a novice with XML and JavaScript, so your assistance would be sincerely appreciated. Thanks.

Do you have the ability to edit the Excel file or is there some reason it has to remain exactly as is before you export it?

2 Answers 2

The format Excel uses for the xml-export depends on the added XML-schema. This can be explicitly created and added or — as I suspect in your case — has been implicitly/ automatically generated by Excel.

Читайте также:  Header code http php

In my example I have two colums, the first one has via XML-Schema to format date-time, the second is normal text and only for the representation in Excel (column format) a date.

Screenshot of an excel-sheet with two columns both containing dates

When I export this as XML I get two seemingly completely different results:

   2009-10-12T00:00:00.000 40098  2000-01-01T00:00:00.000 36526   

When I check the XML-Schema (e.g. with «Debug.Print ActiveWorkbook.XmlMaps(1).Schemas(1).XML») I see the difference (only snippet, not the complete file):

The first column is in the schema of format datetime, the second is varchar. Again, you might not even be aware, how Excel handles your XML-data, since this schema is automatically generated (if I recall correctly in Excel 2003 there was a message indicating that an schema had benn generated for you)

Now how to acomplish this — especially in an existing file: I would try to extract the XML-Schema (see above), save it as something.xsd, adapt the schema according to your needs and import this new Schema. Bummer is you have to set the mapping again (or try this: Excel 2007 XML Source Maps — Refreshing Schemas). Often I let MS Access generate my XML-Schema, i.e. generate the required table, insert some values and exprt the table as XML (ticking the option to add the schema).

I hope this general outline gives you an idea on how to proceed.

Источник

how do i convert to an Excel file to xml file by uploading it using Javascript and call AJAX method?

I gone through some articles in the internet but i couldn’t find any way to convert excel file to xml format. But i have tried this code convert excel to json but i have stuck convert excel file to xml using javascript ,Below i have tried the code to convert excel to json. Can someone help me to convert to xml.

    

0

Hot Network Questions

Subscribe to RSS

To subscribe to this RSS feed, copy and paste this URL into your RSS reader.

Site design / logo © 2023 Stack Exchange Inc; user contributions licensed under CC BY-SA . rev 2023.7.27.43548

By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy.

Источник

Convert Excel to XML in Node.js

Convert Excel to XML in Node.js

Do you have Excel files filled with a massive amount of data and want to convert to XML file format programmatically? Conversion of XLSX/XLS to XML file format is now a matter of a few lines of source code. We will use this JavaScript Excel library to convert Excel to XML in Node.js. In addition, we will write the steps and the code snippet to perform this manipulation and the conversion processes. Therefore, make sure you have installed Node.js on your local machine.

The following points will be covered in this article:

JavaScript Excel library installation#

The installation process of this library is easy and you can jump to the installation section in case of difficulty. There are two ways to enable this API in your project.

First, you can run the following commands to install it:

npm install java npm install aspose.cells 

The other way is to download the API package and enable this library in your Node.js project.

Convert Excel to XML in Node.js#

This library is so powerful and robust due to its enterprise-level features.

You may follow the steps and the code snippet below:

  1. Create an object of the Workbook class and load the source Excel file.
  2. Instantiate an instance of the XmlSaveOptions() class that will be used to save a file in XML file format.
  3. Invoke the save method to save the file.

You can see the output in the image below:

Convert Excel to XML in Node.js

Excel to XML conversion — advanced options#

This section will explore some prominent features offered by this JavaScript Excel library.

Following are the steps and the code snippet:

  1. Instantiate an object of the Workbook class and load the source Excel file.
  2. Create an instance of the XmlSaveOptions class that will be used to save a file in XML file format.
  3. Call the setClearData method that makes the workbook empty after saving the file.
  4. If the value of setCreateDirectory is true, the directory will be automatically created before saving the file.
  5. setCachedFileFolder method is used to store some extensive data.
  6. Call the save method to save the file.

Get a Free License#

You can get a free temporary license to try the API beyond evaluation limitations.

Summing up#

Let’s end this blog post here. We have gone through how to convert Excel to XML in Node.js programmatically. We also have explored some advanced methods exposed by this JavaScript Excel library. Moreover, you can visit the documentation to know other methods. This API will surely help you if you are looking to equip your business application with a robust Excel to XML converter. In fact, conholdate.com is writing new blog posts on other exciting topics. Therefore, please stay in touch for the latest updates.

Ask a question#

You can let us know about your questions or queries on our forum.

FAQs#

How do I get Excel data into XML?

Install this JavaScript Excel library to convert Excel to XML in Node.js programmatically. You can visit the documentation for complete API details.

How do I convert XLSX to XML?

You can check this XmlSaveOptions class to convert XLSX files to XML files programmatically. Further, you can see the list of methods here.

See Also#

Источник

groupdocs-cloud-gists / Convert_Excel_file_to_XML_format_in_NodeJs.js

This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters

// How to Excel File to XML Format Online in Node.js
const convert = async ( ) =>
const convertApi = groupdocs_conversion_cloud . ConvertApi . fromKeys ( clientId , clientSecret ) ;
const settings = new groupdocs_conversion_cloud . ConvertSettings ( ) ;
settings . storageName = myStorage ;
settings . filePath = «nodejs-testing/sample-file.xlsx» ;
settings . format = «xml» ;
settings . outputPath = «nodejs-testing/sample-file.xml» ;
try
// Create convert document request
const request = new groupdocs_conversion_cloud . ConvertDocumentRequest ( settings ) ;
await convertApi . convertDocument ( request ) ;
>
catch ( err )
throw err ;
>
>
convert ( )
. then ( ( ) =>
console . log ( «Successfully converted Excel file to XML format» ) ;
> )
. catch ( ( err ) =>
console . log ( «Error occurred while converting the Excel file:» , err ) ;
> )

You can convert Excel to XML and XML to Excel file programmatically on the cloud. In this article, you will learn how to convert xlsx to xml and xml to xlsx format online in Node.js using REST API.

The following topics shall be covered in this article:

  1. Excel to XML and XML to Excel Conversion API and Node.js SDK
  2. How to Excel File to XML Format Online in Node.js
  3. Convert XML to Excel Online using Node.js REST API
  4. Upload Files on the Cloud and then Download the converted files

This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters

// How to Convert XML to Excel Online using Node.js REST API
const convert = async ( ) =>
const convertApi = groupdocs_conversion_cloud . ConvertApi . fromKeys ( clientId , clientSecret ) ;
const settings = new groupdocs_conversion_cloud . ConvertSettings ( ) ;
settings . storageName = myStorage ;
settings . filePath = «nodejs-testing/sample-file.xml» ;
settings . format = «xlsx» ;
settings . outputPath = «nodejs-testing/sample-file.xlsx» ;
try
// Create convert document request
const request = new groupdocs_conversion_cloud . ConvertDocumentRequest ( settings ) ;
await convertApi . convertDocument ( request ) ;
>
catch ( err )
throw err ;
>
>
convert ( )
. then ( ( ) =>
console . log ( «Successfully converted XML to XLSX file format» ) ;
> )
. catch ( ( err ) =>
console . log ( «Error occurred while converting the XML file:» , err ) ;
> )

This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters

// construct FileApi to download converted file
var fileApi = groupdocs_conversion_cloud . FileApi . fromConfig ( config ) ;
// create donwload file request
let request = new groupdocs_conversion_cloud . DownloadFileRequest ( «nodejs-testing/sample-file.xml» , myStorage ) ;
// download file and response type Stream
fileApi . downloadFile ( request )
. then ( function ( response )
// save file in your system directory
fs . writeFile ( «H:\\groupdocs-cloud-data\\sample-file.xml» , response , «binary» , function ( err ) < >) ;
console . log ( «Expected response type is Stream: » + response . length ) ;
> )
. catch ( function ( error )
console . log ( «Error: » + error . message ) ;
> ) ;

This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters

// open file in IOStream from your system drive.
var resourcesFolder = ‘H:\\groupdocs-cloud-data\\sample-file.xlsx’ ;
// read file
fs . readFile ( resourcesFolder , ( err , fileStream ) =>
// construct FileApi
var fileApi = groupdocs_conversion_cloud . FileApi . fromConfig ( config ) ;
// create upload file request
var request = new groupdocs_conversion_cloud . UploadFileRequest ( «sample-file.xlsx» , fileStream , myStorage ) ;
// upload file
fileApi . uploadFile ( request )
. then ( function ( response )
console . log ( «Expected response type is FilesUploadResult: » + response . uploaded . length ) ;
> )
. catch ( function ( error )
console . log ( «Error: » + error . message ) ;
> ) ;
> ) ;

This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters

# Import Node . js SDK in your node application from http : //api.groupdocs.cloud
global . groupdocs_conversion_cloud = require ( «groupdocs-conversion-cloud» ) ;
global . fs = require ( «fs» ) ;
// get clientId and clientSecret from https://dashboard.groupdocs.cloud (free registration is required).
global . clientId = «xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx» ;
global . clientSecret = «xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx» ;
global . myStorage = «test-internal-storage» ;
const config = new groupdocs_conversion_cloud . Configuration ( clientId , clientSecret ) ;
config . apiBaseUrl = «https://api.groupdocs.cloud» ;

Источник

Оцените статью