I need to set cell type to int. How can I do this?
Just put an integer to that cell.
I may misunderstood your need. Do you want to put a decimal to a cell and just want to show an integer in that cell? You can use Cell.Style.Number or Cell.Style.Custom to set number format.
I wont to put a string to a cell and change type to number format in that cell
I have double myDouble=12345, if I put it to a cell it will value “1,23450+5E” value in the cell. Thsat why I put it in string format: cell.PutValue(String.Format("{0:G}",myDouble), and after that I wont ot change type to number. Or may be when I change format cell value will be “1,23450+5E” again?
You don’t need to put string to that cell and convert it back to integer. Please set number format to that cell.
cell.PutValue(12345);
cell.Style.Number = 0;
@zavoloka,
Aspose.Excel is no more under active development now and is discarded. It is replaced by Aspose.Cells that contains all the features available in different versions of MS Excel. Similarly, it supports the features in its predecessor product. You can set cell type to a variety of types as mentioned in the article Using Built-in Number Formats. Here is an example that demonstrates the setting of the cell type.
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
// Instantiating a Workbook object
Workbook workbook = new Workbook();
// Obtaining the reference of first worksheet
Worksheet worksheet = workbook.Worksheets[0];
// Adding the current system date to "A1" cell
worksheet.Cells["A1"].PutValue(DateTime.Now);
// Getting the Style of the A1 Cell
Style style = worksheet.Cells["A1"].GetStyle();
// Setting the display format to number 15 to show date as "d-mmm-yy"
style.Number = 15;
// Applying the style to the A1 cell
worksheet.Cells["A1"].SetStyle(style);
// Adding a numeric value to "A2" cell
worksheet.Cells["A2"].PutValue(20);
// Getting the Style of the A2 Cell
style = worksheet.Cells["A2"].GetStyle();
// Setting the display format to number 9 to show value as percentage
style.Number = 9;
// Applying the style to the A2 cell
worksheet.Cells["A2"].SetStyle(style);
// Adding a numeric value to "A3" cell
worksheet.Cells["A3"].PutValue(2546);
// Getting the Style of the A3 Cell
style = worksheet.Cells["A3"].GetStyle();
// Setting the display format to number 6 to show value as currency
style.Number = 6;
// Applying the style to the A3 cell
worksheet.Cells["A3"].SetStyle(style);
// Adding a decimal value to "A4" cell
worksheet.Cells["A4"].PutValue(2546.678);
// Getting the Style of the A4 Cell
style = worksheet.Cells["A4"].GetStyle();
//Setting the display format to number 2 to show values as decimal
style.Number = 2;
// Adding a decimal value to "A5" cell
worksheet.Cells["A5"].PutValue(2546);
// Getting the Style of the A5 Cell
style = worksheet.Cells["A5"].GetStyle();
//Setting the display format to number 2 to show values as decimal
style.Number = 0;
// Saving the Excel file
workbook.Save("book1.out.xls", SaveFormat.Excel97To2003);
The latest trial version of this new product can be downloaded here:
Aspose.Cells for .NET (Latest Version)
You can download a complete runnable solution here that can be used to test the features of this product.