使用C#讀取excel文件時遇到一個問題。在我的Excel文件中,一個是DateTime的列,它在Excel文件中的值很長。因此,當我使用C#讀取使用C#的相同值時,Excel會將其轉換爲######格式。任何人都可以請幫忙:我怎樣才能得到日期時間值而不是#####?在C#中讀取excel文件時獲取######值
我的代碼如下所示:
using Excel = Microsoft.Office.Interop.Excel;
Excel.Application xlApp;
Excel.Workbook xlWorkBook;
Excel.Worksheet xlWorkSheet;
object misValue = System.Reflection.Missing.Value;
ExcelObj = new Microsoft.Office.Interop.Excel.Application();
Microsoft.Office.Interop.Excel.Workbook theWorkbook = ExcelObj.Workbooks.Open(oldg.FileName, Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing);
Microsoft.Office.Interop.Excel.Sheets sheets = theWorkbook.Worksheets;
Microsoft.Office.Interop.Excel.Worksheet worksheet = (Microsoft.Office.Interop.Excel.Worksheet)sheets.get_Item(1);
for (int i = 3; i <= worksheet.UsedRange.Rows.Count; i++)
{
var getvalue = excel_getValue("B" + i);
}
調整列的大小? –
調整大小在哪裏?.. –