Author | Topic: Generate Excel (XLSX) and Word (DOCX) | |
---|---|---|
Salvatore Megna | Generate Excel (XLSX) and Word (DOCX) on Thu, 13 Feb 2020 11:18:21 +0100 Hi, what do you use for generate files xlsx or docx? Some third part library? thanks boys | |
Jonathan Leeming | Re: Generate Excel (XLSX) and Word (DOCX) on Thu, 13 Feb 2020 08:49:55 -0700 On 2/13/2020 3:18 AM, Salvatore Megna wrote: > Hi, > what do you use for generate files xlsx or docx? Some third part library? > > thanks boys Hi, I use Xbase++ with ActiveX connecting to Excel or Word. As long as Excel / Word are installed on the workstation you can use this method. The create an Excel file the basic steps are... oXls := CreateObject("Excel.Application") Open Excel oBook := oXls:workbooks:Add() Open new blank Workbook oSheet := oBook:ActiveSheet Select Sheet1 oSheet:Cells(1,3):Value := "Some Value" Write "Some Value" to C3 nRow := 5 nCol := 2 * The following would set B5 to 12 oSheet:Cells((nRow),(nCol)):Value := 12 aData := {{0,1,1},; {2,5,8},; {13,21,34}} *The following would set the 9 cells to the values in aData oRange := oSheet:Range("A8","C10") oRange:Value := aData *or if you don't need the same range for anything else... oSheet:Range("A8","C10"):Value := aData *To Save the spreadsheet file oBook:SaveAs("C:\SomePath\SomeFile.xlsx") oBook := oSheet := NIL oXls:quit() Quit & Exit from Excel oXls:destroy() destroy excel object Using the ActiveX you can do most anything that you can manually from within Excel. If I'm stuck on how to do something programmatically I usually open excel and record a macro to do what I need and then inspect the VB code and convert it to Xbase++. Not that when updating a spreadsheet the fewer AxtiveX call you make the faster it runs so rather than updating individual cells update ranges of cells from an array of values. (the aData example above) There is an ActiveX section within this newsgroup. Alaska has some samples too... Documents\Xbase++\source\samples\activex\msexcel This link helps me with working with the Excel object... https://docs.microsoft.com/en-us/office/vba/api/overview/Excel/object-model Excel has many constants and using the Xbase++ tool these can be put into a header file... Tlb2Ch.exe "Excel.Application" > excel.ch Using the oWord := CreateObject("Word.Application") you could similarly work with Word documents. There are 3rd party libraries that can create Excel spreadsheets without having to have Excel installed but I have yet had a need to use them. Hope this helps... Jonathan jonathan.leeming@familycentre.org Edmonton, Alberta, Canada | |
Jim Lee | Re: Generate Excel (XLSX) and Word (DOCX) on Fri, 14 Feb 2020 07:29:45 +0100 hi you can try hbxlsxwriter https://github.com/riztan/hbxlsxwriter it is for harbour and i have not test it yet with Xbase++ --- there is a old Solution from Phil Ide to use HTML which Excel will open. have to search for it | |
Jorge L. Borlando | Re: Generate Excel (XLSX) and Word (DOCX) on Tue, 25 Feb 2020 12:38:00 -0300 hello I have made a library that generates excel xml files and if necessary you can generate an xlsx output but you need to have excel installed, each cell supports almost all the formats allowed in excel, if you are interested we see it privately jlborlando@gmail.com regards "Salvatore Megna" escribió en el mensaje de noticias:38a21ae7$3f3dfa10$12b120@news.alaska-software.com... Hi, what do you use for generate files xlsx or docx? Some third part library? thanks boys | |
Daniel Faus | Re: Generate Excel (XLSX) and Word (DOCX) on Mon, 27 Apr 2020 20:21:01 +0200 El 13/02/2020 a las 11:18, Salvatore Megna escribió: > Hi, > what do you use for generate files xlsx or docx? Some third part library? > > thanks boys Hi Salvatore... I'm using EXpress library for Alaska Xbase from Donnay Software... http://donnay-software.com/ds/index.htm DC_Excel2Array( <cFileName>, [<bEval>] ) -> aData It stores the xls into an array, and you have the viceversa... DC_Array2Excel( [<cExcelFile>], ; <aData>, ; [<nOrientation>], ; [<lDisplayAlerts>], ; [<lVisible>], ; [<lAutoFit>], ; [<lTrimNilColumns>], ; [<lCombineSheets>], ; [<cPassWord>], ; [<lFreezeRow1>], ; [<lCSVFallBack>], ; [<aSheetCaptions>] ) -> lStatus You have to intalled Excel in your system. Other way is using ActiveX directly oExcel := CreateObject("Excel.Application") IF Empty( oExcel ) Mensaje( "Excel not esta instalado" ) RETURN(NIL) ENDIF oBook := oExcel:workbooks:Open(DATOS+"pedido.xls") oExcel:DisplayAlerts := .F. oExcel:visible := .F. oSheet := oBook:ActiveSheet MaxRec := oSheet:Range("a2"):CurrentRegion:Rows:Count Recorremos las filas de la tabla Excel. DO WHILE nRow < MaxRec If !Empty(oSheet:Cells(nRow,7):Value) CODIGO Select lstArticulos Seek (oSheet:Cells(nRow,7):Value) If Found() ? "El articulo Existe "+(oSheet:Cells(nRow,7):Value) nExiste++ Actualiza la barra de progreso DC_GetProgress(oProgress, nRow++, MaxRec+1, Int(MaxRec/100) ) Else tmpDESCR := IIF( !Empty(oSheet:Cells(nRow,9):Value) , (oSheet:Cells(nRow,9):Value) , "") tmpPVENT := IIF( !Empty(oSheet:Cells(nRow,32):Value), (oSheet:Cells(nRow,32):Value), 0 ) tmpPCOST := IIF( !Empty(oSheet:Cells(nRow,31):Value), (oSheet:Cells(nRow,31):Value), 0 ) tmpREFER := IIF( !Empty(oSheet:Cells(nRow,7):Value) , (oSheet:Cells(nRow,7):Value) , "") tmpFULC := cFecha tmpTIPO := IIF( !Empty(oSheet:Cells(nRow,11):Value), (oSheet:Cells(nRow,11):Value), "") tmpTEMP := IIF( !Empty(oSheet:Cells(nRow,6):Value) , (oSheet:Cells(nRow,6):Value) , "") tmpADICI := IIF(!Empty((oSheet:Cells(nRow,12):Value)), AllTrim(Transform((oSheet:Cells(nRow,12):Value),"@X")), "")+" "+; IIF(!Empty((oSheet:Cells(nRow,16):Value)), AllTrim(Transform((oSheet:Cells(nRow,16):Value),"@X")), "")+" "+; IIF(!Empty((oSheet:Cells(nRow,17):Value)), AllTrim(Transform((oSheet:Cells(nRow,17):Value),"@X")), "")+" "+; IIF(!Empty((oSheet:Cells(nRow,18):Value)), AllTrim(Transform((oSheet:Cells(nRow,18):Value),"@X")), "") ... this is two ideas... Daniel |