Query analyzer comes with Excel quickly completes an example of exporting data from SQL Server ("from cocosoft)

xiaoxiao2021-03-06  75

Specific steps: 1. Start Visual Studio, create a new project, select Visual C # items, console applications, and determine. 2. Select "Solution Explorer", select the project, click Right click, select Add Reference, "COM" option page, "Microsoft Excel 11.0 Object Library, click" Select "OK". 3, use the following code instead of the "main" method: Excel.Application Excel; Excel._Workbook XBK; Excel._Worksheet Xst; Excel._QueryTable XQT; String Conn = "ODBC; Driver = SQL Server; Server = Nb; User ID = SA; Database = xiaoshou "; string select =" SELECT S.LIUSHUI AS "S.Yhname AS Bank account, S.YHPJHM AS Bank Bill Number, S.YHRQ AS Bank Notes Date, S.YHJE AS Bank Bill Amount from yinhang y, yhdata s where y.yhbh = S.YHBH "; Excel = new excel.Applicationclass (); xbk = excel.workbooks.add (true); xst = (Excel._worksheet) XBK.Activesheet; Excel. Cells [2, 2] = "Sales list"; 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.name = "black body"; xst.get_range (Excel.cells [2, 2, 2], Excel.cells [2, 2]). Font.size = 22; xqt = xst.querytables.add (conn, xst.get_range (Excel.cells [4, 2], excel.cells [4, 2]), select); xqt.name = "Export all sales details"; XQT .Fieldnames = true; xqt.rownumbers = false; xqt.filladjacentformulas = false; xqt.preserveformatting = false; xqt.backgroundQuery = true; xqt.refreshstyl e = Excel.XlCellInsertionMode.xlInsertDeleteCells; xQt.AdjustColumnWidth = true; xQt.RefreshPeriod = 0; xQt.PreserveColumnInfo = true; xQt.Refresh (xQt.BackgroundQuery); excel.Visible = true; 4, generating, generating solutions 5, run

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

New Post(0)