9CBS - Document Center - .NET Title C # Call Operation Excel A Cocosoft (Original) Keyword Excel C # call
I would like to write a little bit of articles here, but because of time relationship, I have not been written. Now, a little thing you have, C # calls Excel's source code to make a report here to give you a look. Regarding the composition of the code, there is already a complete code annotation in the source code, which is nothing here. In this class, the main function is to read the data from the database, and after setting the format, it is displayed in Excel. This is the rendering after running: In this class, there are two parameters passed, one is its data source, the other is the title string of the entire report, and the code should be understood.
using System; using System.Data; using Excel; namespace LogicLayer {///
Row [color ();}}} // // load a total of a total bank // 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; // // Set Color // Xst.get_Range (Excel.cells [ Rowsum, colsum], excel.cells [rowsum, colorex]). select (); xst.get_range (Excel.cells [Rowsum, Colsum], Excel.cells [Rowsum, Colindex]). Interior.colorIndex = 19; // Set to light yellow, a total of 56 types // // acquired the title // Excel.cells [2, 2] = Str; // // 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 // / / Set the report form to the most adaptive width // xst.get_range (Excel.cells [4, 2], Excel.cells [Rowsum, ColIndex]). Select (); xst.get_range (Excel.cells [4 , 2], Excel.cells [ROWSUM, Colindex]). Column.autofit (); // Setting the title of the entire report is the cross-column center // xst.get_range (Excel.cells [2, 2, 2], Excel. Cells [2, Colindex]). SELECT (); xst.get_range (Excel.cel) LS [2, 2], Excel.cells [2, Colindex]). Horizontalalignment = Excel.xlhalign.xlhaligncenteraCrossSselection; // // Draw Border // xst.get_range (Excel.cells [4, 2], Excel.cells [ Rowsum, Colindex]). Borders.LineStyle = 1; Xst.get_Range (Excel.cells [4, 2], Excel.cells [Rowsum, 2]). Borders [Excel.xlbordersindex.xledgeleft] .Weight = Excel.xlborderweight. XLTHICK; // Set the left cable plus thick xst.get_range (Excel.cells [4, 2], Excel.cells [4, Colindex]). Borders [Excel.xlbordersindex.xledgeTGetop] .weight = Excel.xlborderweight.xlt; / Set the upper side line plus xst.get_range (Excel.cells [4, ColIndex], Excel.cells [Rowsum, ColIndex]). Borders [Excel.xlbordersindex.xledgeright] .Weight = Excel.xlborderweight.xlt;