C# 開啟EXCEL 如何儲存

來源:互聯網
上載者:User

m_objExcel = new Excel.Application();
m_objExcel.Visible = true;

Excel.Workbook m_objBook = m_objExcel.Application.Workbooks.Add(FileWrite);
m_objBook = m_objExcel.Workbooks.Add(Missing.Value);

Excel.Worksheet m_objSheet = (Excel.Worksheet)(m_objBook.Worksheets[1]);

m_objRange = m_objSheet.get_Range("A5", Type.Missing);

//存放報表資料的二維數組
object[,] objdate = new object[rownum, 9];

.......................

.......................
m_objRange = m_objSheet.get_Range("A5", Missing.Value);
m_objRange = m_objRange.get_Resize(rownum, 9);
//水平對齊--靠右對齊
m_objRange.HorizontalAlignment = Excel.XlHAlign.xlHAlignRight;
//文字格式設定
m_objRange.NumberFormat = "@";
m_objRange.Value2 = objdate;

//儲存並施放EXECL資源

m_objBook.Saved = true;
m_objExcel.DisplayAlerts = false;

m_objSheet._Saves (FileWrite,Missing.Value,Missing.Value,Missing.Value,Missing.Value, 
        Missing.Value,Missing.Value,Missing.Value,Missing.Value);       
m_objBook.Close(false, Missing.Value, Missing.Value);
if (m_objExcel != null)
{
m_objExcel.Workbooks.Close();
m_objExcel.Quit();
System.Runtime.InteropServices.Marshal.ReleaseComObject(m_objExcel);
System.GC.Collect();
}

if (m_objSheet != null)
{
System.Runtime.InteropServices.Marshal.ReleaseComObject(m_objSheet);
System.GC.Collect();

GC.Collect();

這樣寫可以 VS2008測試通過

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.