VSFLEXGRID data is transferred to Excel

xiaoxiao2021-03-31  224

Engineering Reference Description: The use of this code is based on Microsoft Excel 2003, not tested on other versions of office, so the Microsoft Excel 11.0 code should be referenced in VB. Other content descriptions: This code uses vsFlexGRID as source data And you can name the name of the Excel workfill, where the first segment code is in a new Excel workbook, while the second is to save the content into an existing workbook. In order to display the progress, I use a form that displays progress, FRMPBAR, can remove the relevant segment code. Public Sub GridToExcel (srcGrid As VSFlexGrid, shName As String) 'Grid export the data to Excel spreadsheet Dim i As Integer Dim j As Integer Dim appXL As Variant Dim wb As Excel.Workbook Dim sh As Excel.Worksheet Dim rng, RNG1, RNG2 AS Excel.Range On Error Goto Errhandler Set Appxl = CreateObject ("Excel.Application") SET WB = AppxL.Workbooks.Add () wb.activate set sh = wb.Worksheets.Add () sh.name = shName FRMPBAR.CAPTION = "Export data, please wait ..." frMpBar.show for i = 0 to srcgrid.rows - 1 for j = 1 to srcgrid.cols - 1 sh.cells (i 1, J) = srcgrid.cell (FlexCPText, i, j) DOEvents next j next i unload frmpbar appxl.visible = true exit suberrhandler: msgbox err.description end sub

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

New Post(0)