ASP.NET Turn Excel

xiaoxiao2021-03-06  105

Using system; using system.data; using Excel;

A summary description of Namespace Xmlteest {///

/// Class1. /// Public class class1 {public class1 (data) {/// Todo: Add constructor logic to add

Excel.Application Excel; Int rowindex = 4; int colorex = 1;

Excel._Workbook XBK; Excel._Worksheet XST;

Excel = new excel.applicationclass () ;; xbk = excel.workbooks.add (true); xst = (Excel._Worksheet) xbk.activesheet;

// // get the title // foreach (Datacolumn col in dv.table.columns) {Colindex ; Excel.cells [4, ColIndex] = columnname; xst.get_range (Excel.cells [4, ColIndex], Excel. Cells [4, ColIndex]). Horizontalalignment = Excel.xlvalign.xlvalignCenter; // Set the title format to be aligned}

// // Number of data in the table {RowIndex ; colIndex = 1; Foreach (Datacolumn col in dv.table.columns) {Colindex ; if (col.DataType == System.Type.gettype ("system.datetime")) {Excel.cells [RowIndex, COLINDEX] = (CONVERT.TODATETIME (Row [Col.columnName] .tostring ())). TOSTRING ("YYYY-MM-DD" ); Xst.get_Range (Excel.cells [RowIndex, ColIndex], Excel.cells [RowIndex, Colindex]). Horizontalalignment = Excel.xlvalign.xlvalignCenter; // Setting the date-type field format to center alignment} else IF (col.. DataType == System.Type.gettype ("System.String")) {Excel.cells [RowIndex, ColIndex] = "'" row [col.columnname] .tostring (); xst.get_range (Excel.cells [RowIndex , colIndex], excel.Cells [rowIndex, colIndex]) HorizontalAlignment = Excel.XlVAlign.xlVAlignCenter;. // format field character is centered} else {excel.Cells [rowIndex, colIndex] = row [col.ColumnName ] .Tostring ();}}} // // load a total of a total line // int ROWSUM = RowIndex 1; int COLSUM = 2; Excel.cells [ROWSUM , 2] = "Total"; xst.get_range (Excel.cells [Rowsum, 2], Excel.cells [Rowsum, 2]). Horizontalalignment = Excel.xlhalign.xlhalignCenter; // // Settings Color / / Xst.get_range (Excel.cells [Rowsum, Colsum], Excel.cells [Rowsum, ColIndex]). Select (); xst.get_range (Excel.cells [Rowsum, Colsum], Excel.cells [Rowsum, ColIndex]) .Interior.colorindex = 19; // set to light yellow, total 56 species // // Excel.cells [2, 2] = str; // set the title format of the entire report // xst.get_range (Excel.cells [2, 2], Excel.cells [2, 2]). Font.Bold = true; xst.get_range (Excel.cells [2, 2], Excel.cells [2, 2]). Font.size = 22;

转载请注明原文地址:https://www.9cbs.com/read-103407.html

New Post(0)