
ExcelWriter V1.01 für PB3.94
-neu CreateFile komplett überarbeitet ist jetzt PB kompatibel
http://www.purebasicpower.de/?ExcelWriter
Code: Alles auswählen
XLS_CreateFile("i:\excel\pbTest.xls")
XLS_PrintGridLines(#False)
XLS_SetMargin(#XLS_TopMargin, "1.5") ; set to 1.5 inches
XLS_SetMargin(#XLS_LeftMargin, "1.5")
XLS_SetMargin(#XLS_RightMargin, "1.5")
XLS_SetMargin(#XLS_BottomMargin, "1.5")
XLS_SetFont("Arial",10,#XLS_NoFormat)
XLS_SetFont("Arial",10,#XLS_Bold)
XLS_SetFont("Arial",10,#XLS_Bold|#XLS_Underline)
XLS_SetFont("Arial",18,#XLS_Italic)
XLS_SetColumnWidth(0,0,50)
XLS_SetDefaultRowHeight(16)
XLS_SetRowHeight(0,24)
XLS_SetRowHeight(1,24)
XLS_SetHeader("This is the header")
XLS_SetFooter("This is the footer")
;Eine CSV-Datei ins Excelformat konvertieren
i.l = 0
zeile.s =""
If ReadFile(0, "i:\aut\tiplan.csv")
While ~Eof(0)
i = i + 1
zeile = ReadString()
XLS_WriteText(zeile, i, 1, #XLS_Font0, #XLS_RightAlign, #XLS_CellNormal, #XLS_Bold)
Wend
CloseFile(0)
XLS_CloseFile()
EndIf
End
das ist so gewollt, dass Du alle Felder einer CSV-Zeile in die erste Spalte desKarl hat geschrieben:Ich habe mal versucht, eine CSV-Datei in das Excelformat zu konvertieren:Code: Alles auswählen
XLS_WriteText(zeile, i, 1, #XLS_Font0, #XLS_RightAlign, #XLS_CellNormal, #XLS_Bold)
Code: Alles auswählen
#xlAddIn = $00000012
#xlCSV = $00000006
#xlCSVMac = $00000016
#xlCSVMSDOS = $00000018
#xlCSVWindows = $00000017
#xlDBF2 = $00000007
#xlDBF3 = $00000008
#xlDBF4 = $0000000B
#xlDIF = $00000009
#xlExcel2 = $00000010
#xlExcel2FarEast = $0000001B
#xlExcel3 = $0000001D
#xlExcel4 = $00000021
#xlExcel5 = $00000027
#xlExcel7 = $00000027
#xlExcel9795 = $0000002B
#xlExcel4Workbook = $00000023
#xlIntlAddIn = $0000001A
#xlIntlMacro = $00000019
#xlWorkbookNormal = $FFFFEFD1
#xlSYLK = $00000002
#xlTemplate = $00000011
#xlCurrentPlatformText = $FFFFEFC2
#xlTextMac = $00000013
#xlTextMSDOS = $00000015
#xlTextPrinter = $00000024
#xlTextWindows = $00000014
#xlWJ2WD1 = $0000000E
#xlWK1 = $00000005
#xlWK1ALL = $0000001F
#xlWK1FMT = $0000001E
#xlWK3 = $0000000F
#xlWK4 = $00000026
#xlWK3FM3 = $00000020
#xlWKS = $00000004
#xlWorks2FarEast = $0000001C
#xlWQ1 = $00000022
#xlWJ3 = $00000028
#xlWJ3FJ3 = $00000029
#xlUnicodeText = $0000002A
#xlHtml = $0000002C
#xlWebArchive = $0000002D
#xlXMLSpreadsheet = $0000002E
;
;===================================
; Excel object
;===================================
;
Prototype.l Excel_FileToObject(szFileName.s)
Prototype.l Excel_Destroy(hObject.l)
Prototype.l Excel_GetSheetCount(hObject.l)
Prototype.l Excel_GetSheetName(hObject.l, nSheet.l)
;
;===================================
; XLTable
;===================================
;
Prototype.l Excel_SheetToXLTable(hObject.l, nSheet.l)
Prototype.l Excel_XLTable_GetMaxCols(hXLTable.l)
Prototype.l Excel_XLTable_GetMaxRows(hXLTable.l)
Prototype.l Excel_XLTable_CellIsValue(hXLTable.l, nCol.l, nRow.l)
Prototype.l Excel_XLTable_GetCellAsString(hXLTable.l, nCol.l, nRow.l)
Prototype.d Excel_XLTable_GetCellAsValue(hXLTable.l, nCol.l, nRow.l)
Prototype.d Excel_XLTable_GetCellAsValueEx(hXLTable.l, nCol.l, nRow.l, nRound.l)
Prototype.f Excel_XLTable_GetCellAsSingle(hXLTable.l, nCol.l, nRow.l)
Prototype.f Excel_XLTable_GetCellAsSingleEx(hXLTable.l, nCol.l, nRow.l, nRound.l)
Prototype.l Excel_XLTable_PutOnClipBoard(hXLTable.l)
;
;===================================
; Miscellaneous
;===================================
;
Prototype.l Excel_SaveSheetAs(szFileName.s, szFileOut.s, nxlFileType.l, nSheet.l)
Prototype.l App_GetVersionString()
;
;===================================
; Helpfunction
;===================================
;
Procedure.s GetBSTR(pBSTR.l)
ProcedureReturn PeekS(pBSTR.l,SysStringByteLen_(pBSTR.l) )
EndProcedure
Procedure XLTable_Init()
Shared XLTablehModul.l
XLTablehModul = OpenLibrary(#PB_Any, "XLTable.dll")
If XLTablehModul
Global Excel_FileToObject.Excel_FileToObject = GetFunction(XLTablehModul, "Excel_FileToObject")
Global Excel_Destroy.Excel_Destroy = GetFunction(XLTablehModul, "Excel_Destroy")
Global Excel_GetSheetCount.Excel_GetSheetCount = GetFunction(XLTablehModul, "Excel_GetSheetCount")
Shared Excel_GetSheetName_.Excel_GetSheetName
Excel_GetSheetName_ = GetFunction(XLTablehModul, "Excel_GetSheetName")
Global Excel_SheetToXLTable.Excel_SheetToXLTable = GetFunction(XLTablehModul, "Excel_SheetToXLTable")
Global Excel_XLTable_GetMaxCols.Excel_XLTable_GetMaxCols = GetFunction(XLTablehModul, "Excel_XLTable_GetMaxCols")
Global Excel_XLTable_GetMaxRows.Excel_XLTable_GetMaxRows = GetFunction(XLTablehModul, "Excel_XLTable_GetMaxRows")
Global Excel_XLTable_CellIsValue.Excel_XLTable_CellIsValue = GetFunction(XLTablehModul, "Excel_XLTable_CellIsValue")
Shared Excel_XLTable_GetCellAsString_.Excel_XLTable_GetCellAsString
Excel_XLTable_GetCellAsString_ = GetFunction(XLTablehModul, "Excel_XLTable_GetCellAsString")
Global Excel_XLTable_GetCellAsValue.Excel_XLTable_GetCellAsValue = GetFunction(XLTablehModul, "Excel_XLTable_GetCellAsValue")
Global Excel_XLTable_GetCellAsValueEx.Excel_XLTable_GetCellAsValueEx = GetFunction(XLTablehModul, "Excel_XLTable_GetCellAsValueEx")
Global Excel_XLTable_GetCellAsSingle.Excel_XLTable_GetCellAsSingle = GetFunction(XLTablehModul, "Excel_XLTable_GetCellAsSingle")
Global Excel_XLTable_GetCellAsSingleEx.Excel_XLTable_GetCellAsSingleEx = GetFunction(XLTablehModul, "Excel_XLTable_GetCellAsSingleEx")
Global Excel_XLTable_PutOnClipBoard.Excel_XLTable_PutOnClipBoard = GetFunction(XLTablehModul, "Excel_XLTable_PutOnClipBoard")
Global Excel_SaveSheetAs.Excel_SaveSheetAs = GetFunction(XLTablehModul, "Excel_SaveSheetAs")
Shared App_GetVersionString_.App_GetVersionString
App_GetVersionString_ = GetFunction(XLTablehModul, "App_GetVersionString")
EndIf
ProcedureReturn XLTablehModul
EndProcedure
Procedure XLTable_End()
Shared XLTablehModul.l
If XLTablehModul
CloseLibrary(XLTablehModul)
EndIf
EndProcedure
Procedure.s Excel_GetSheetName(hObject.l, nSheet.l)
Shared Excel_GetSheetName_.Excel_GetSheetName
ProcedureReturn GetBSTR(Excel_GetSheetName_(hObject, nSheet))
EndProcedure
Procedure.s Excel_XLTable_GetCellAsString(hXLTable.l, nCol.l, nRow.l)
Shared Excel_XLTable_GetCellAsString_.Excel_XLTable_GetCellAsString
ProcedureReturn GetBSTR(Excel_XLTable_GetCellAsString_(hXLTable, nCol, nRow))
EndProcedure
Procedure.s App_GetVersionString()
Shared App_GetVersionString_.App_GetVersionString
ProcedureReturn GetBSTR(App_GetVersionString_())
EndProcedure