C# 操作EXCEL樣式 樣本 --產生EXCEL審計表

來源:互聯網
上載者:User
C# 操作EXCEL樣式 樣本 --產生EXCEL審計表

 #region 產生審計表        public static void GenerateAccountGrid(        string fileName,         string tableName,         string companyName,         string owner,         DateTime endline,         string copyMan, AnalysisEnt ent)        {            try            {                DataTable dt = new DataTable();                dt.Columns.Add(tableName);                dt.Columns.Add("");                dt.Columns.Add("");                dt.Columns.Add("");                dt.Columns.Add("");                dt.Columns.Add("");                //AddNewRow(ref dt, 6, "", "", "", tableName, "", "");                AddNewRow(ref dt, 6, "被審計單位名稱:", companyName, "編製人:" + owner, "", "日期: " + DateTime.Now.ToShortDateString(), "");                AddNewRow(ref dt,  6, "會計週期或到期日:" + endline, "", "複製人:" + copyMan, "", "索引號:" + "YIZK-" + DateTime.Now.Millisecond.ToString());                AddNewRow(ref dt, 6, " ", " ", " ", " ", "頁次: 1", "");                AddNewRow(ref dt, 6, "項目名稱", "期末未審計數", "摘要", "賬項調整", "重分類調整", "期末審定數");                AddNewRow(ref dt, 6, ent.ProName, ent.UnFinishNum, ent.FinishNum, ent.Summary, "0", "0", ent.FinishNum);                AddNewRow(ref dt, 6, "審計結論:", " ", " ", " ", " ", " ");                ExcelHelper.ExportToExcel(dt, fileName, tableName);                if (File.Exists(fileName))                {                    Microsoft.Office.Interop.Excel.Application xlsApp = new Microsoft.Office.Interop.Excel.Application();                    Microsoft.Office.Interop.Excel.Workbook workbook = xlsApp.Workbooks.Open(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.Worksheet mySheet = workbook.Sheets[tableName] as Microsoft.Office.Interop.Excel.Worksheet;                    xlsApp.Visible = true;                    ////標題樣式                    ((Microsoft.Office.Interop.Excel.Range)mySheet.Columns["A:F", System.Type.Missing]).ColumnWidth = 20;                    Microsoft.Office.Interop.Excel.Range titleRange = mySheet.get_Range("A1", "F1");                    titleRange.ClearContents();                    titleRange.Merge(0);                    titleRange = mySheet.get_Range("A1", "A1");                    titleRange.Cells[1, 1] = tableName;                    titleRange.Font.Size = 30;                    titleRange.HorizontalAlignment = Microsoft.Office.Interop.Excel.XlHAlign.xlHAlignCenter;                    titleRange.Borders.get_Item(Microsoft.Office.Interop.Excel.XlBordersIndex.xlEdgeBottom).                    Weight = Microsoft.Office.Interop.Excel.XlBorderWeight.xlMedium;                    ////為所有儲存格添加邊框                    Microsoft.Office.Interop.Excel.Range allRange = mySheet.get_Range("A1", "F7");                    allRange.Borders.LineStyle = 1;                    allRange.Borders.get_Item(Microsoft.Office.Interop.Excel.XlBordersIndex.xlEdgeTop).                    LineStyle = Microsoft.Office.Interop.Excel.XlLineStyle.xlContinuous;                    ////最後一行儲存格合并                    Microsoft.Office.Interop.Excel.Range contentRange = mySheet.get_Range("A7", "F7");                    contentRange.ClearContents();                    contentRange.Merge(0);                    contentRange = mySheet.get_Range("A7", "F7");                    contentRange[1, 1] = "審計結論:";                    contentRange.RowHeight = 30;                    contentRange.VerticalAlignment = Microsoft.Office.Interop.Excel.XlVAlign.xlVAlignTop;                }            }            catch (Exception ex)            {                MessageBox.Show(ex.Message);            }        }        public static void AddNewRow(ref DataTable dt, int columnCount, params string[] cells)        {            if (cells == null || cells.Length > columnCount)            {                return;            }            DataRow dr = dt.NewRow();            for (int i = 0; i < cells.Length; i++)            {                dr[i] = cells[i];            }            dt.Rows.Add(dr);        }        #endregion

以上就是C# 操作EXCEL樣式 樣本 --產生EXCEL審計表的內容,更多相關內容請關注topic.alibabacloud.com(www.php.cn)!

  • 相關文章

    聯繫我們

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