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

Free Support Forum - aspose.com

Format cells before put value

I'm using Aspose.Cells for .Net 5.1.0.0.

Before I put value into certain cell, I want to set data format. For example, data value typeis DateTime, I want to set date format in the cell to "mm/dd/yyyy hh:mm". Like in MS excel, right click the cell and click "format cells", in "number" tab I can select date and corresponding format.

I did not find any functions to implement this. maybe there is similar post in this forum, but I have not found it.

Plz advise how to do this.

Thank you.

Code:

Cell cell = worksheet.Cells[1, 1];

//todo: set date format in this cell

cell.PutValue(val);

Hi,

See the following sample code for your reference:

Workbook excel = new Workbook();
// Create a Cells object obtaining all the cells of the first
// Worksheet.
Cells cells = excel.Worksheets[0].Cells;
// Create a Cell object and get the A1 cell.
Aspose.Cells.Cell cell = cells[0, 0];
//Create a style object.
Style style = cell.GetStyle();
style.Custom = “mm/dd/yyyy hh:mm”;
cell.SetStyle(style);
// Put date value into it.
cell.PutValue(DateTime.Now);

excel.Worksheets[0].AutoFitColumn(0);

excel.Save(“e:\test\output.xls”);

For complete reference about how to set formatting to cells, see the document:
Data Formatting

Thank you.