嗨,有开发人员,
我正在尝试使用Progress 4GL将大量数据导出到Excel。我们谈论的是±5500条记录和±170列。 问题是这对Excel来说太过分了,它引发了以下错误:Excel error。 我可以继续并导出所有数据,但是程序并不完全可以在中间出现错误。
我正在使用以下代码将来自不同CSV文件的所有数据导出到一个单独的Excel文件中,并为每个CSV文件添加单独的工作表:
/* Initialize Excel file & add new workbook */
CREATE "Excel.Application" vchExcel.
vchExcel:SheetsInNewWorkbook = NUM-ENTRIES(ipcSheets,',').
vchExcel:WorkBooks:ADD().
ASSIGN vchWorkBook = vchExcel:WorkBooks:Item(1).
/* Import each file's data into a new sheet of the workbook */
Sheet:
DO iTab = 1 TO NUM-ENTRIES(ipcFiles) ON ERROR UNDO, RETRY Sheet:
/* Import CSV data into Excel */
ASSIGN cConnection = SUBSTITUTE("TEXT;" + gvcExportPath + "csv_files\" + "&1",ENTRY(iTab,ipcFiles))
vchWorkSheet = vchExcel:Sheets:ITEM(iTab)
vchWorkSheet:NAME = ENTRY(iTab,ipcSheets)
lResult = vchWorkSheet:QueryTables:ADD(cConnection,vchWorkSheet:cells(1,1)).
ASSIGN
vchQueryTable = vchWorkSheet:QueryTables(1)
vchQueryTable:FieldNames = TRUE
vchQueryTable:RowNumbers = FALSE
vchQueryTable:FillAdjacentFormulas = FALSE
vchQueryTable:PreserveFormatting = FALSE
vchQueryTable:RefreshOnFileOpen = FALSE
vchQueryTable:RefreshStyle = 1
vchQueryTable:SavePassword = FALSE
vchQueryTable:SaveData = TRUE
vchQueryTable:AdjustColumnWidth = TRUE
vchQueryTable:RefreshPeriod = 0
vchQueryTable:TextFilePromptOnRefresh = FALSE
vchQueryTable:TextFilePlatform = 437
vchQueryTable:TextFileStartRow = 1
vchQueryTable:TextFileParseType = 1
vchQueryTable:TextFileTextQualifier = 1
vchQueryTable:TextFileConsecutiveDelimiter = TRUE
vchQueryTable:TextFileTabDelimiter = TRUE
vchQueryTable:TextFileSemicolonDelimiter = TRUE
vchQueryTable:TextFileCommaDelimiter = FALSE
vchQueryTable:TextFileSpaceDelimiter = FALSE
vchQueryTable:TextFileTrailingMinusNumbers = TRUE
lResult = vchQueryTable:REFRESH
vchQueryTable:BackgroundQuery = FALSE.
/* Catch all errors */
CATCH eAnyError AS Progress.Lang.ERROR:
RUN disp_mesg(INPUT SUBSTITUTE("ERROR! -> &1",eAnyError:GetMessage(1))).
RUN adnew_log(INPUT SUBSTITUTE("ERROR OCCURRED!")).
RUN adnew_log(INPUT SUBSTITUTE("=> &1: &2",eAnyError:GetMessageNum(1),eAnyError:GetMessage(1))).
END CATCH.
END.
/* Save & close */
vchExcel:Visible = FALSE.
vchExcel:DisplayAlerts = FALSE.
vchWorkBook:SaveAs(gvcExportPath + ipcName + '.xlsx',,,,,,).
vchWorkBook:CLOSE().
/* Release All Objects */
RELEASE OBJECT vchQueryTable NO-ERROR.
RELEASE OBJECT vchWorkSheet NO-ERROR.
RELEASE OBJECT vchWorkBook NO-ERROR.
vchExcel:QUIT(). /* Quit Excel */
RELEASE OBJECT vchExcel NO-ERROR.
您是否知道如何解决此问题并获得所需结果?提前谢谢!
答案 0 :(得分:0)
为什么从进度控制XL?
如果XL是强制性步骤......我宁愿这样做...用一个宏文件调用XL来打开CSV并以XL格式保存。 如果需要将其集成到业务流程中......我只需在生成CSV后立即使用宏文件打开XL。