為何我轉出的Excel數值列不能加總,好像全變成字符一樣。我轉excel函數如下。大家幫看看有什麼問題沒有?急。
/*
* 此了函數用於把單表中的數據轉出excel
*/
static public void ExportToExcel(object[] columName, object[] fieldName, System.Data.DataTable dt, string Name)
{
try
{
Excel.Application app = new Excel.Application();
_Workbook wkb = app.Workbooks.Add(XlWBATemplate.xlWBATWorksheet);
_Worksheet wks = (_Worksheet)wkb.ActiveSheet;
wks.Name = Name;
wks.Visible = XlSheetVisibility.xlSheetVisible;
Range wksRange;
string[] cellValue = new string[columName.Length];
string[] cellValue1 = new string[columName.Length];
//加欄位名
for (int i = 0; i <= columName.Length - 1; i++)
cellValue1[i] = columName[i].ToString();
wksRange = wks.get_Range(wks.Cells[1, 1], wks.Cells[1, fieldName.Length]);
#if OFFICEXP
wksRange.set_Value(Missing.Value, cellValue1);
#else
wksRange.Value = cellValue1;
#endif
&nbs