db2 - Export SQL query results into a multi tabbed Excel spreadsheet -
I want to write a set of query selects 100 DB2 10.1 to return all the rows in each table in the database And the result is exported to Excel spreadsheets with a new tab for each result set Is this possible and if so, how can I do this? At the moment I only way to do that, I do think that is exported to set each result and then manually copying each tab multi-tab spreadsheet Thank you
After
You can use APIs for Excel with scripting languages like VB scripts.
'class that used to export Excel file set xls = CreateObject (result set "square format" EasyXLS.ExcelDocument "):
VBS this with a code XlsAutoFormat = CreateObject ("EasyXLS.ExcelAutoFormat") for xlsAutoFormat.InitAs (AUTOFORMAT_EASYXLS1) query = 1 to 100 'Add a new sheet xls.easy_addWorksheet_2 ("Sheet" and query) Set xlsSheet = xls to be same as cells should be similar XlsAutoFormat set. easy_getSheetAt (Q - 1) "Create record set object dim objResultSet set objResultSet = CreateObject (" ADODB.Recordset ") objResultSet.Open query string, objDBConnection Set the result that is set in the list set the lstRows will store the values of lstRows = CreateObject ("EasyXLS.Util.List") Add the header in the list Add the dim lstHeaderRow set lstHeaderRow = CreateObject ("EasyXLS LstHeaderRow.addElement (" Column 1 " ) lstHeaderRow.addElement ( "column 2") lstHeaderRow.addElement ( "column objResultSet.EOF Add inventory values from the database 3") lstRows.addElement (lstHeaderRow) 'Switch = true set RowList = CreateObject ( "EasyXLS.Util.List ") RowList.addElement (" "& amp; In objResultSet ( "Column 1")) RowList.addElement ( "" & amp; objResultSet ( "Column 2")) RowList.addElement ( "" & amp; objResultSet ( "3 columns")) lstRows.addElement (RowList) ' Move the next record objResultSet.MoveNext Loop xlsSheet.easy_insertList_2 lstRows, xlsAutoFormat set the next export result in Excel file xls.easy_WriteXLSFile ("c: \ result set.xls")
This link Also see
If you select a non-scripting language, then there are methods in the API, which can directly insert data from the result set and the lists can be omitted. See another sample.
Comments
Post a Comment