简体   繁体   中英

C# Aspose.Cells set data to Excel file with format

I have search around the web but could not find any solution. I have a Excel file used as a template, with a area to parse data from DB. Among the columns of the Excel file, there is a number column with a custom format. My code (C#) of setting data to Excel file is as below:

Aspose.Cells.Worksheet ws;
Aspose.Cells.Range rg;
...
rg = ws.Cells.CreateRange("A1", "M10");
var setData = genDataArray(dt); //this function convert Datatable to 2D object array
rg.Value = setData;

Another attempt is also a failure:

ws.Cells.ImportDataTable(dt, false, "A1");

The code works fine. Data is set correctly to the Excel file, but without any format of the Excel file.

When I click the cells of Excel file (after the process), and press Enter, the value is formatted with the style I previously set in the Excel file.

How can i make the Aspose to apply the format I set in the Excel file?

Thank in advance.

After varous attempts, I finally found an solution.

The number column of inputted DataTable have data type of String, so i guess Aspose set it to the Excel file as Text value.

After changing it to Decimal type, the value is correctly formatted.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM