在Excel中,如果某個單元格的內容是數字,且比較長,默認情況下,會變為科學計數發表示,例如:123456789123456000會被表示為1.2345E+17,為了能夠將數字按照普通的格式完全表示,就需要設置單元格的屬性 ,下面是例子代碼:
Excel.Application m_objExcel = null;
Excel._Workbook m_objBook = null;
Excel.Sheets m_obJSheets = null;
Excel._Worksheet m_obJSheet = null;
Excel.Range m_objRange = null;
object m_objOpt = System.Reflection.Missing.Value;
try
{
m_objExcel = new Excel.Application();
m_objBook = m_objExcel.Workbooks.Open("e:\\1.xls", m_objOpt, m_objOpt, m_objOpt,
m_objOpt, m_objOpt, m_objOpt, m_objOpt, m_objOpt, m_objOpt, m_objOpt,
m_objOpt, m_objOpt, m_objOpt, m_objOpt);
m_obJSheets = (Excel.Sheets)m_objBook.Worksheets;
m_objSheet = (Excel._Worksheet)(m_obJSheets.get_Item(1));
m_objRange = m_obJSheet.get_Range("A1", m_objOpt);
m_objRange.NumberFormatLocal = "#";
m_objBook.SaveAs("e:\\22.xls", m_objOpt, m_objOpt,
m_objOpt, m_objOpt, m_objOpt, Excel.XlSaveAsAccessMode.xlNoChange,
m_objOpt, m_objOpt, m_objOpt, m_objOpt, m_objOpt);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
m_objBook.Close(m_objOpt, m_objOpt, m_objOpt);
m_objExcel.Workbooks.Close();
m_objExcel.Quit();
System.Runtime.InteropServices.Marshal.ReleaseComObject(m_objBook);
System.Runtime.InteropServices.Marshal.ReleaseComObject(m_objExcel);
m_objBook = null;
m_objExcel = null;
GC.Collect();
}