我有這個C#代碼將數據集轉換爲xlsx。有沒有辦法設置創建的xlsx文件的工作表的單元格或列寬?如何在編程創建的xlsx文件中設置單元格的寬度?
//Get the filename
String filepath = args[0].ToString();
//Convert the file to dataset
DataSet ds = Convert(filepath.ToString(), "tblCustomers", "\t");
//Create the excell object
Excel.Application excel = new Excel.Application();
//Create the workbook
Excel.Workbook workBook = excel.Workbooks.Add();
//Set the active sheet
Excel.Worksheet sheet = workBook.ActiveSheet;
int i = 0;
foreach (DataRow row in ds.Tables[0].Rows)
{
for (int j = 0; j < row.ItemArray.Length; j++)
{
sheet.Cells[i + 1, j + 1] = row[j];
}
i++;
}
workBook.SaveAs(@"C:\fromCsv.xlsx");
workBook.Close();
是的它是完美的。謝謝 – themis 2012-01-31 13:00:38