VS2010, NPOI 2.0.6.0 [stable]
There are five overload methods for setting data in a cell.
```
void SetCellValue(bool value);
void SetCellValue(DateTime value);
void SetCellValue(double value);
void SetCellValue(IRichTextString value);
void SetCellValue(string value);
```
When We set
```
SetCellValue(1); // Numeric value it is coming exactly as 1
```
When We set
```
SetCellValue("1"); // Numeric value but set as string it is coming '1
//Error: Notice the leading single quote.
```
Complete Code sample
```
class Program
{
static void Main(string[] args)
{
InitializeWorkbook();
ISheet sheet1 = hssfworkbook.CreateSheet("Sheet1");
sheet1.CreateRow(0).CreateCell(0).SetCellValue("This is a Sample");
int x=1;
for (int i = 1; i <= 15; i++)
{
IRow row=sheet1.CreateRow(i);
for (int j = 0; j < 15; j++)
{
//Some of my nulric values are in string
//Hence changing the type to string.
row.CreateCell(j).SetCellValue("" + x +"");
x++;
}
}
WriteToFile();
}
static HSSFWorkbook hssfworkbook;
static void WriteToFile()
{
//Write the stream data of workbook to the root directory
FileStream file = new FileStream(@"test.xls", FileMode.Create);
hssfworkbook.Write(file);
file.Close();
}
static void InitializeWorkbook()
{
hssfworkbook = new HSSFWorkbook();
////create a entry of DocumentSummaryInformation
DocumentSummaryInformation dsi = PropertySetFactory.CreateDocumentSummaryInformation();
dsi.Company = "NPOI Team";
hssfworkbook.DocumentSummaryInformation = dsi;
////create a entry of SummaryInformation
SummaryInformation si = PropertySetFactory.CreateSummaryInformation();
si.Subject = "NPOI SDK Example";
hssfworkbook.SummaryInformation = si;
}
}
```
Any way to get rid of that ?
Thanks in Advance.
Comments: ** Comment from web user: sudhAnsu63 **
There are five overload methods for setting data in a cell.
```
void SetCellValue(bool value);
void SetCellValue(DateTime value);
void SetCellValue(double value);
void SetCellValue(IRichTextString value);
void SetCellValue(string value);
```
When We set
```
SetCellValue(1); // Numeric value it is coming exactly as 1
```
When We set
```
SetCellValue("1"); // Numeric value but set as string it is coming '1
//Error: Notice the leading single quote.
```
Complete Code sample
```
class Program
{
static void Main(string[] args)
{
InitializeWorkbook();
ISheet sheet1 = hssfworkbook.CreateSheet("Sheet1");
sheet1.CreateRow(0).CreateCell(0).SetCellValue("This is a Sample");
int x=1;
for (int i = 1; i <= 15; i++)
{
IRow row=sheet1.CreateRow(i);
for (int j = 0; j < 15; j++)
{
//Some of my nulric values are in string
//Hence changing the type to string.
row.CreateCell(j).SetCellValue("" + x +"");
x++;
}
}
WriteToFile();
}
static HSSFWorkbook hssfworkbook;
static void WriteToFile()
{
//Write the stream data of workbook to the root directory
FileStream file = new FileStream(@"test.xls", FileMode.Create);
hssfworkbook.Write(file);
file.Close();
}
static void InitializeWorkbook()
{
hssfworkbook = new HSSFWorkbook();
////create a entry of DocumentSummaryInformation
DocumentSummaryInformation dsi = PropertySetFactory.CreateDocumentSummaryInformation();
dsi.Company = "NPOI Team";
hssfworkbook.DocumentSummaryInformation = dsi;
////create a entry of SummaryInformation
SummaryInformation si = PropertySetFactory.CreateSummaryInformation();
si.Subject = "NPOI SDK Example";
hssfworkbook.SummaryInformation = si;
}
}
```
Any way to get rid of that ?
Thanks in Advance.
Comments: ** Comment from web user: sudhAnsu63 **
Some Numeric values in my object comes as string formatted.
Converting them back to Int/double is cumbersome.