开发者

How to update Excel cell value "2009.03" instead of "2009.3"

I am updating a Excel Worksheet cell value to 2009.03 and it become change to 2009.3.

I tried may ways to solve the issue but value always changed to "2009.3" instead of "2009.03" on Server. It is working on my system but not on Win XP 2003 Server System.

I used to set excel cell NumberFormat to "@", "0.00", "####.##" and even tried to concatenated "'" before value but result not come. The excel file is of 2007 format(.xlsx). >My Code is

Microsoft.Office.Interop.Excel.Workbook WorkBook = null;
Microsoft.Office.Interop.Excel.Worksheet Sheet = null;
WorkBook = Utility.GetWorkbook2007(templateFileWPath);
Sheet = (Microsoft.Office.Interop.Excel.Worksheet)WorkBook.Worksheets[1];
Microsoft.Office.Interop.Excel.Range TPCellRange = (Microsoft.Office.Interop.Excel.Range)Sheet.Cells[this.GetRowIndex(Sheet, this.CellAddress), this.GetColumnIndex(Sheet, this.CellAddress)];
TPCellRange.set_Value(Microsoft.Office.Interop.Excel.XlRangeValueDataType.xlRangeValueDefault,"2009.03");

or also tried

CellValueRange.NumberFormat 开发者_Go百科= "@";
CellValueRange.set_Value(Microsoft.Office.Interop.Excel.XlRangeValueDataType.xlRangeValueDefault, "2009.03");


This seems strange. Could it be interpreting the number as a date (and formatting the month with and without the leading zero)? Do you use a period as a date separator in your culture (or more specifically, in the culture either machine is set to)?

Also, I'm not familiar with the Excel API, but the functions you're using sound more like you are trying to set a range, rather than set the value in a cell.


What happens if you do the following?

TPCellRange.Formula = 2009.03;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜