We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

How to formatt the cell as "Text"

Hi All,

Using ASPOSE i am trying to Export the Data to Excel, here the problem is in case if the number contains more than 15 digits it is rounding off to the nearest zero.

I used "0" and "@" to formatt the cell still there is no use.

But while usage of "@" , cell is formatting to text but data in the cell is formatting to nearest zero.

Could anybody help me to resolve this?

Suresh

Hi Suresh,

Well, I think that is the behavior of MS Excel. You can manually confirm it in MS Excel too. If you have numeric data with more than 15 digits, when you enter into MS Excel it will just try to round 16th or more digits to zero. I think one way to you can do it if you have string data.

e.g

Workbook workbook = new Workbook();
Worksheets worksheets = workbook.Worksheets;
Worksheet worksheet = workbook.Worksheets[0];

//Now insert the data into the column cells or import data to the cells.
//I use import data table.

DataTable dataTable = new DataTable(“Products”);
//Adding columns to the DataTable object
dataTable.Columns.Add(“field1”, typeof(Int32));
dataTable.Columns.Add(“field2”, typeof(string));

//Creating an empty row in the DataTable object
DataRow dr = dataTable.NewRow();
//Adding data to the row
dr[0] = 1;
dr[1] = “1234567899876543”;
//Adding filled row to the DataTable object
dataTable.Rows.Add(dr);

//Creating another empty row in the DataTable object
dr = dataTable.NewRow();
//Adding data to the row
dr[0] = 2;
dr[1] = “1234567891234569”;
//Adding filled row to the DataTable object
dataTable.Rows.Add(dr);

//Don’t insert new rows to paste the datatable data, just use the exising cells in the
//worksheet cells.
worksheet.Cells.ImportDataTable(dataTable, true, 0, 0, false);

//Save the excel file.
workbook.Save(“f:\test\output_testtextformat2.xls”);


Thank you.