C # Operations Excel style example-Generate Excel Audit table

Source: Internet
Author: User
C # Operations Excel style example-Generate Excel Audit table

 #region Generate audit table public static void Generateaccountgrid (String fileName, String tableName, St            Ring 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, "audited by unit name:", CompanyName, "compilation person:" + owner, "", "Date:" + DateTime.Now.ToShortDateString (), ""); Addnewrow (ref DT, 6, "fiscal period or due Date:" + EndLine, "", "Copy person:" + Copyman, "", "index number:" + "yizk-" + DateTime.Now.Millisecon                D.tostring ());                Addnewrow (ref DT, 6, "", "", "", "", "page: 1", ""); Addnewrow (ref DT, 6, "project name", "Final unaudited number", "Summary"," Adjustment of Accounts "," reclassification Adjustment "," Final approval number "); Addnewrow (ref DT, 6, Ent. Proname, Ent. Unfinishnum, Ent. Finishnum, Ent. Summary, "0", "0", Ent.                Finishnum);                Addnewrow (ref DT, 6, "Audit conclusion:", "", "", "", "", "");                Excelhelper.exporttoexcel (DT, fileName, tableName); if (file.exists (FileName)) {Microsoft.Office.Interop.Excel.Application Xlsapp = new Mic Rosoft.                    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;          Heading Style ((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;                    Add a border for all cells 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;                    The last row of cells merges 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] = "Audit conclusion:";                    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

The above is the C # operation Excel Style example-build the content of Excel audit table, more related content please pay attention to topic.alibabacloud.com (www.php.cn)!

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    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.