日期:2014-05-17  浏览次数:21002 次

操作excel文件怎么在末尾追加?

private void ExportToExcel(string FileName)
        {
            if (FileName.IndexOf(".") <= 0)
            {
                FileName = FileName + ".xls";
            }
            else
            {
                string[] str = FileName.Split('.');
                if (str.Length > 2)
                {
                    FileName = str[0] + str[str.Length - 1];
                }
            }


            Excel.Application app;
            try
            {
                app = new Excel.Application();
            }
            catch 
            {
             ClsCommFuncs.Alert("没有安装Excel程序或者安装错误");
                return;
            }
            app.Workbooks.Add(true);
            app.Visible = false;

            Excel.Workbooks books = (Excel.Workbooks)app.Workbooks;
            Excel.Workbook book = (Excel.Workbook)books.Add(Type.Missing);

            int iget = 1;
            int dwindex = 0;
            //写头
            if (panelHide1.Visible == true)
            {
                foreach (DataGridViewColumn datcol in dgvLog.Columns)
                {
                    app.Cells[iget,&