C#操作Excel檔案~對已有的Excel檔案操作

來源:互聯網
上載者:User

標籤:c#對excel的操作

如果我希望達到的目的是我所操作產生的資料添加在已有的Excel表裡想到方法有2:

1.複製表裡所有資料刪除表,建立表,之前的資料+新資料放入

2.想法讀取Excel表

採取方法2:

功能二:對已有的Excel檔案操作

前提和上一篇文章是相同的

/// <summary>        /// 對已有的EXCEL檔案操作        /// </summary>        static void ModifyExcelFile()        {            //已經存在的Excel            string excelFilePath = "E:\\VS項目路徑\\測試產生EXCEL2\\MyText.xls";             //初始化            MSExcel.Application myExcel = new MSExcel.ApplicationClass();                                    object oMissing = System.Reflection.Missing.Value;            //讀取EXCEL模板            MSExcel.Workbook myBook = myExcel.Application.Workbooks.Open(excelFilePath, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing);            //使用第一個工作表作為插入資料的工作表            MSExcel.Worksheet mySheet = (MSExcel.Worksheet)myBook.Worksheets[1];            //賦值            mySheet.Cells[1, 1] = "test"; //給excel中的第5行和第5列賦值  表頭就是第1行                                          //給已有資料的地方賦值會覆蓋                        myBook.Close(true, oMissing, oMissing); // 儲存修改後的excel            myExcel.Quit();         }
備忘:可以產生Excel的圖表、PPT,有興趣可以自己查

C#操作Excel檔案~對已有的Excel檔案操作

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.