jerome Posted September 2, 2010 Share Posted September 2, 2010 Hi all, I'm back with an Excel file generation UDF that can manage multi-sheet workbook but without the need to have Excel installed on the computer... You can add more functions if you want but keep always my name in the post of greetings. expandcollapse popup;---------------------------------------------------------------------------------------------- ; Copyright Jerome DERN 2010 ; --------------------------------------------------------------------------------------------- #Include <File.au3> ; Const for cell format Const $XMLXLS_STRING = "String" Const $XMLXLS_NUMBER = "Number" Const $XMLXLS_SDATE = "Short Date" Const $XMLXLS_PERCENT = "Percent" Const $XMLXLS_SCIENTIFIC= "Scientific" Const $XMLXLS_DATE = "[$-F400]h:mm:ss\ AM/PM" Const $XMLXLS_FRACTION = "#" "?/?" Const $XMLXLS_COMPTAB = "_-* #,##0.00\ "€"_-;\-* #,##0.00\ "€"_-;_-* "-"??\ "€"_-;_-@_-" ; Constants for cell alignment Const $XMLXLS_CENTER = "Center" Const $XMLXLS_RIGHT = "Right" Const $XMLXLS_LEFT = "Left" Const $XMLXLS_BOTTOM = "Bottom" Const $XMLXLS_TOP = "Top" Const $XMLXLS_JUSTIFIED = "Justify" ; Font style Global Enum Step *2 $XMLXLS_BOLD, $XMLXLS_ITALIC, $XMLXLS_STRIKETHROUGH, $XMLXLS_UNDERLINE, $XMLXLS_SUBSCRIPT, $XMLXLS_SUPERSCRIPT ; BitOr Values for border Global Enum Step *2 $XMLXLS_BDRIGHT, $XMLXLS_BDLEFT, $XMLXLS_BDTOP, $XMLXLS_BDBOTTOM, $XMLXLS_BDCROSS1, $XMLXLS_BDCROSS2 ; Page Set up Const $XMLXLS_LANDSCAPE = "Landscape" Const $XMLXLS_PORTRAIT = "Portrait" $demo1 = True $file = FileOpen("text.xls", 2) ; Create Workbook, active sheet will be se second one (2) _XLSCreateWorkbook($file, 2) ; Define styles _XLSCreateStyles($file) ; Define a new personal style _XLSAddStyle($file, "Header", "Arial", 11, $XMLXLS_BOLD, "000000", "", $XMLXLS_CENTER, $XMLXLS_CENTER, BitOR($XMLXLS_BDRIGHT, $XMLXLS_BDLEFT, $XMLXLS_BDTOP, $XMLXLS_BDBOTTOM)) _XLSAddStyle($file, "Table", "Arial", 11, 0, "000000", "", $XMLXLS_LEFT, $XMLXLS_CENTER, BitOR($XMLXLS_BDRIGHT, $XMLXLS_BDLEFT, $XMLXLS_BDTOP, $XMLXLS_BDBOTTOM)) ; Finish style definition _XLSCloseStyles($file) ; In demo1 case the sheets are generated from an array in memory ; limitation: named area can't be defined If $demo1 Then ; a typical excel sheet memory reservation (can be adjusted to real need) Dim $Sheet1[65536][255] Dim $Sheet2[65536][255] ; Create sheet 1 _XLSInitSheet($Sheet1, "Page 1") _XLSSetRowHeight($Sheet1, 1, 40) _XLSSetColumnWidth($Sheet1, 1, 100) _XLSSetColumnWidth($Sheet1, 2, 110) _XLSSetColumnWidth($Sheet1, 3, 120) _XLSSetCell($Sheet1, 1, 1, "Qty", "", "", "Header") _XLSSetCell($Sheet1, 1, 2, "Value", "", "", "Header") _XLSSetCell($Sheet1, 1, 3, "Total", "", "", "Header") _XLSSetCell($Sheet1, 2, 1, 2, "", $XMLXLS_NUMBER, "Table", "qty") _XLSSetCell($Sheet1, 2, 2, 4, "", $XMLXLS_NUMBER, "Table", "value") ;_XLSSetCell($Sheet1, 2, 3, 0, "RC[-2]*RC[-1]", $XMLXLS_NUMBER, "Table") _XLSSetCell($Sheet1, 2, 3, 0, "qty*value", $XMLXLS_NUMBER, "Table") _XLSGenerateFromArray($file, $Sheet1, $XMLXLS_LANDSCAPE) ; Create sheet 2 _XLSInitSheet($Sheet2, "Page 2") _XLSSetCell($Sheet2, 1, 1, "Name", "", "", "Header") _XLSSetCell($Sheet2, 1, 2, "Value", "", "", "Header") _XLSSetCell($Sheet2, 2, 1, "Beer", "", $XMLXLS_STRING, "Table") _XLSSetCell($Sheet2, 2, 2, 4.0, "", $XMLXLS_NUMBER, "Table") _XLSGenerateFromArray($file, $Sheet2) Else ; in this demo, sheets are generated from direct commands to library ; Create a new worksheet _XLSAddWorkSheet($file, "Sheet1") ; Define specific names of this sheet (optional) _XLSCreateWSNames($file) ; Print area is a specific name for printing zone _XLSAddWSName($file, "Print_Area", "Sheet1!R1C1:R65535C255") ; Finish definition of names _XLSCloseWSNames($file) ; Start Worksheet content _XLSStartWSDefinition($file) ; Create a row _XLSAddRowInWorkSheet($file) ; Add data to first row, column 1 _XLSAddCellInRow($file, "C1", "", $XMLXLS_STRING, "Table") ; Add data to first row, column 2 _XLSAddCellInRow($file, "C2", "", $XMLXLS_STRING) ; Finish row definition _XLSCloseRow($file) ; Create a new row (2nd one) _XLSAddRowInWorkSheet($file) ; Add data to second row, column 1 _XLSAddCellInRow($file, "1", "", $XMLXLS_NUMBER) ; Add data to second row, column 2 _XLSAddCellInRow($file, "2", "RC[-1]*2", $XMLXLS_NUMBER) ; Finish row definition _XLSCloseRow($file) ; Close Worksheet content _XLSCloseWorkSheet($file, $XMLXLS_PORTRAIT, 1, 1, 1, 1, 0.5, 0.5) ; Add a second Worksheet _XLSAddWorkSheet($file, "Sheet2") _XLSStartWSDefinition($file) ; Create first row definition _XLSAddRowInWorkSheet($file) ; Add data to first row, column 1 _XLSAddCellInRow($file, "CC1", "", $XMLXLS_STRING) ; Add data to first row, column 2 _XLSAddCellInRow($file, "CC2", "", $XMLXLS_STRING) ; Finish row definition _XLSCloseRow($file) ; Close Worksheet content _XLSCloseWorkSheet($file) EndIf ; Close Worksbook content, file is ready to use _XLSCloseWorkBook($file) ShellExecute("text.xls") ; ------------------------------------------------------------------------------------------------------------------------------------- ; ------------------------------------------------------- ARRAY TO XML PRIMITIVES ----------------------------------------------------- ; ------------------------------------------------------------------------------------------------------------------------------------- ; ----------------------------------------------------------------------------------- ; Initialize sheet : Set sheet name and set active size to 1 cell ; ----------------------------------------------------------------------------------- Func _XLSInitSheet(ByRef $array, $name) ; $array[0][0] store the name of the sheet;the maximum row number used;the maximum column number used $array[0][0] = $name & ";1;1" EndFunc ; ----------------------------------------------------------------------------------- ; Set row height ; ----------------------------------------------------------------------------------- Func _XLSSetRowHeight(ByRef $array, $row, $height) ; array[x][0] store the height of each row $array[$row][0] = $height EndFunc Func _XLSSetColumnWidth(ByRef $array, $col, $width) ; array[0][x] store the width of each column $array[0][$col] = $width EndFunc ; ------------------------------------------------------------------------------------ ; This format a cell in case of an array usage + generation with _XLSGenerateFromArray function ; ------------------------------------------------------------------------------------ Func _XLSSetCell(ByRef $array, $row, $col, $data, $formulae, $type=$XMLXLS_STRING, $style="Default", $name="") Local $decode If $formulae<>"" Then $data="" if $type = "" Then $type = $XMLXLS_STRING If $style = "" Then $style = "Default" $array[$row][$col] = $data & @CR & $formulae & @CR & $type & @CR & $style & @CR & $name ; check if max of row and column are to be updated $decode = StringSplit($array[0][0], ";") If $decode[0]<3 Then Return If $row>$decode[2] Then $decode[2]=$row If $col>$decode[3] Then $decode[3]=$col $array[0][0]=$decode[1]&";"&$decode[2]&";"&$decode[3] EndFunc ; ---------------------------------------------------------------------------------- ; Generate a sheet from a 2D array. array[0][0] has the sheet name, other array[row][col] ; are strings formatted using _XLSBuildCell function ; ---------------------------------------------------------------------------------- Func _XLSGenerateFromArray($file, ByRef $array, $orientation=$XMLXLS_PORTRAIT, $mbottom = 0.98, $mleft=0.78, $mright=0.78, $mtop=0.98, $hmargin=0.5, $fmargin=0.5) Local $col, $row, $sname, $decode, $data, $formula, $type, $style, $name, $height ; get array real size $decode = StringSplit($array[0][0], ";") If $decode[0] < 3 Then Return $sname = $decode[1] $maxrow = $decode[2] $maxcol = $decode[3] ; Create a new worksheet _XLSAddWorkSheet($file, $sname) ; Define specific names of this sheet (optional) _XLSCreateWSNames($file) ; Print area is a specific name for printing zone _XLSAddWSName($file, "Print_Area", "'"&$sname&"'" & "!R1C1:R"&$maxrow&"C"&$maxcol) ; Small patch in order to Manage here named cells Local $temp = $file, $nbnames=0 Dim $cellnames[1000][2] $file =_TempFile() ; Finish definition of names _XLSCloseWSNames($file) ; Start Worksheet content _XLSStartWSDefinition($file) ; Write column size if needed For $col=1 to $maxcol If $array[0][$col] <> "" Then _XLSColumnSize($file, $col, $array[0][$col]) Next ; generate sheet content For $row=1 to $maxrow $height = -1 If $array[$row][0] <> "" Then $height = $array[$row][0] ; Create a row _XLSAddRowInWorkSheet($file, $height) For $col=1 to $maxcol $data = "" $formula = "" $type = $XMLXLS_STRING $style = "Default" $name = "" If $array[$row][$col]<>"" Then $e = StringSplit($array[$row][$col], @CR) If $e[0]=5 Then $data = $e[1] $formula = $e[2] $type = $e[3] $style = $e[4] $name = $e[5] ;, named cell not yet implemented If $name<>"" Then $cellnames[$nbnames][0] = $name $cellnames[$nbnames][1] = "'"&$sname&"'"&"!R"&$row&"C"&$col $nbnames+=1 EndIf EndIf EndIf If $type="" Then $type = $XMLXLS_STRING If $style="" Then $style = "Default" ; Add data to first row, column 1 _XLSAddCellInRow($file, $data, $formula, $type, $style) Next ; Finish row definition _XLSCloseRow($file) Next ; Add named cell found For $col=1 to $nbnames _XLSAddWSName($temp, $cellnames[$col-1][0], $cellnames[$col-1][1]) Next ; merge files Dim $aRecords _FileReadToArray($file,$aRecords) FileDelete($file) $file = $temp For $col = 1 to $aRecords[0] FileWriteLine($file, $aRecords[$col]) Next ; Close Worksheet content _XLSCloseWorkSheet($file, $orientation, $mbottom, $mleft, $mright, $mtop, $hmargin, $fmargin) EndFunc ; ------------------------------------------------------------------------------------------------------------------------------------- ; ------------------------------------------------------- XML BASE PRIMITIVES --------------------------------------------------------- ; ------------------------------------------------------------------------------------------------------------------------------------- ; -------------------------------------------------------------------------------------------------- ; Create (Define) a new Excel workbook ; -------------------------------------------------------------------------------------------------- Func _XLSCreateWorkbook($file, $activesheet=1) If IsString($file) Then FileDelete($file) $activesheet -= 1 FileWriteLine($file, '<?xml version="1.0"?>') FileWriteLine($file, '<Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet" xmlns:html="http://www.w3.org/TR/REC-html40">') FileWriteLine($file, '<DocumentProperties xmlns="urn:schemas-microsoft-com:office:office"><Author>XLSXMLGenerator</Author><Created>'&@YEAR&'-'&@MON&'-'&@MDAY&'T'&@HOUR&':'&@MIN&':'&@SEC&'</Created><Company>XLSXML</Company></DocumentProperties>') FileWriteLine($file, '<ExcelWorkbook xmlns="urn:schemas-microsoft-com:office:excel"><ActiveSheet>'&$activesheet&'</ActiveSheet></ExcelWorkbook>') EndFunc ; -------------------------------------------------------------------------------------------------- ; Create (Define) a Style section ; -------------------------------------------------------------------------------------------------- Func _XLSCreateStyles($file) FileWriteLine($file, ' <Styles>') FileWriteLine($file, ' <Style ss:ID="Default" ss:Name="Normal"><Alignment ss:Vertical="Bottom"/><Borders/><Font ss:Size="11"/></Style>') EndFunc ; -------------------------------------------------------------------------------------------------- ; Create (Define) a new style. Borders must be constructed with BitOR() of desired border attribute ; -------------------------------------------------------------------------------------------------- Func _XLSAddStyle($file, $name="S21", $font="Arial", $size=11, $fstyle=0, $pcolor="000000", $icolor="", $AlignHor=$XMLXLS_CENTER, $AlignVer=$XMLXLS_BOTTOM, $Border=0) Local $f, $fontfam="Swiss" FileWriteLine($file, ' <Style ss:ID="' & $name &'">') FileWriteLine($file, ' <Alignment ss:Horizontal="' & $AlignHor & '" ss:Vertical="' & $AlignVer &'"/>') ;$Border = BitOR($XMLXLS_BDRIGHT, $XMLXLS_BDLEFT, $XMLXLS_BDTOP, $XMLXLS_BDBOTTOM, $XMLXLS_BDCROSS1, $XMLXLS_BDCROSS2) If $Border>0 Then FileWriteLine($file, ' <Borders>') If BitAnd($Border, $XMLXLS_BDBOTTOM)>0 Then FileWriteLine($file, ' <Border ss:Position="Bottom" ss:LineStyle="Continuous" ss:Weight="1"/>') If BitAnd($Border, $XMLXLS_BDLEFT)>0 Then FileWriteLine($file, ' <Border ss:Position="Left" ss:LineStyle="Continuous" ss:Weight="1"/>') If BitAnd($Border, $XMLXLS_BDRIGHT)>0 Then FileWriteLine($file, ' <Border ss:Position="Right" ss:LineStyle="Continuous" ss:Weight="1"/>') If BitAnd($Border, $XMLXLS_BDTOP)>0 Then FileWriteLine($file, ' <Border ss:Position="Top" ss:LineStyle="Continuous" ss:Weight="1"/>') If BitAnd($Border, $XMLXLS_BDCROSS1)>0 Then FileWriteLine($file, ' <Border ss:Position="DiagonalLeft" ss:LineStyle="Continuous" ss:Weight="1"/>') If BitAnd($Border, $XMLXLS_BDCROSS2)>0 Then FileWriteLine($file, ' <Border ss:Position="DiagonalRight" ss:LineStyle="Continuous" ss:Weight="1"/>') If $Border>0 Then FileWriteLine($file, ' </Borders>') $f = ' <Font ss:FontName="' & $font & '" x:Family="' & $fontfam & '" ss:Size="' & $size & '" ' ;$fstyle = BitOR($XMLXLS_BOLD, $XMLXLS_ITALIC, $XMLXLS_STRIKETHROUGH, $XMLXLS_UNDERLINE, $XMLXLS_SUBSCRIPT) If BitAnd($fstyle, $XMLXLS_BOLD)>0 Then $f &= 'ss:Bold="1" ' If BitAnd($fstyle, $XMLXLS_ITALIC)>0 Then $f &= 'ss:Italic="1" ' If BitAnd($fstyle, $XMLXLS_STRIKETHROUGH)>0 Then $f &= 'ss:StrikeThrough="1" ' If BitAnd($fstyle, $XMLXLS_UNDERLINE)>0 Then $f &= 'ss:Underline="Single" ' If BitAnd($fstyle, $XMLXLS_SUBSCRIPT)>0 Then $f &= 'ss:VerticalAlign="Subscript" ' If BitAnd($fstyle, $XMLXLS_SUPERSCRIPT)>0 Then $f &= 'ss:VerticalAlign="Superscript" ' If $pcolor <>"" Then $f &= 'ss:Color="#'&$pcolor&'" ' $f &= '/>' If $icolor<>"" Then FileWriteLine($file, '<Interior ss:Color="#'&$icolor&'" ss:Pattern="Solid"/>') FileWriteLine($file, $f) FileWriteLine($file, ' </Style>') EndFunc ; -------------------------------------------------------------------------------------------------- ; Close styles definitions ; -------------------------------------------------------------------------------------------------- Func _XLSCloseStyles($file) FileWriteLine($file, ' </Styles>') EndFunc ; -------------------------------------------------------------------------------------------------- ; Create (Define) a new Excel worksheet ; -------------------------------------------------------------------------------------------------- Func _XLSAddWorkSheet($file, $sheet) FileWriteLine($file, ' <Worksheet ss:Name="' & $sheet & '">') EndFunc ; -------------------------------------------------------------------------------------------------- ; Create (Define) an range named section ; -------------------------------------------------------------------------------------------------- Func _XLSCreateWSNames($file) FileWriteLine($file, ' <Names>') EndFunc ; -------------------------------------------------------------------------------------------------- ; Create (Define) a new range name ; -------------------------------------------------------------------------------------------------- Func _XLSAddWSName($file, $name="Print_Area", $location="'Sheet1'!R1C1:R65535C255") FileWriteLine($file, ' <NamedRange ss:Name="' & $Name & '" ss:RefersTo="=' & $location & '"/>') ; Ex: <NamedRange ss:Name="qty" ss:RefersTo="='Page 1'!R2C1"/> ; Ex: <NamedRange ss:Name="value" ss:RefersTo="='Page 1'!R2C2"/> EndFunc ; -------------------------------------------------------------------------------------------------- ; Close Worksheet named range section ; -------------------------------------------------------------------------------------------------- Func _XLSCloseWSNames($file) FileWriteLine($file, ' </Names>') EndFunc ; -------------------------------------------------------------------------------------------------- ; Begin WorkSheet definition ; -------------------------------------------------------------------------------------------------- Func _XLSStartWSDefinition($file) FileWriteLine($file, ' <Table x:FullColumns="1" x:FullRows="1">') EndFunc ; -------------------------------------------------------------------------------------------------- ; Define column size ; -------------------------------------------------------------------------------------------------- Func _XLSColumnSize($file, $col, $size) FileWriteLine($file, ' <Column ss:Index="'&$col&'" ss:AutoFitWidth="0" ss:Width="'&$size&'"/>') EndFunc ; -------------------------------------------------------------------------------------------------- ; Add a new row in current worksheet ; -------------------------------------------------------------------------------------------------- Func _XLSAddRowInWorkSheet($file, $height=-1) If $height = -1 Then FileWriteLine($file, ' <Row ss:AutoFitHeight="1">') Else FileWriteLine($file, ' <Row ss:AutoFitHeight="0" ss:Height="'& $height &'">') EndIf EndFunc ; -------------------------------------------------------------------------------------------------- ; Add a cell (column) in the cirrent row of the current worksheet ; -------------------------------------------------------------------------------------------------- Func _XLSAddCellInRow($file, $data, $formula="", $type=$XMLXLS_STRING, $style="Default") Local $Cell =' <Cell ' If $formula <> "" Then $Cell &= 'ss:Formula="=' & $formula & '" ' ; formulae example: RC[-1]*2 or R1C1*2 ; formulae example: Sheet2!R[1]C*2 FileWriteLine($file, $Cell & 'ss:StyleID="' & $style & '"><Data ss:Type="' & $type & '">' & $data & '</Data></Cell>') EndFunc ; -------------------------------------------------------------------------------------------------- ; Close current row definition ; -------------------------------------------------------------------------------------------------- Func _XLSCloseRow($file) FileWriteLine($file, ' </Row>') EndFunc ; -------------------------------------------------------------------------------------------------- ; Close current worksheet definition ; -------------------------------------------------------------------------------------------------- Func _XLSCloseWorkSheet($file, $orientation=$XMLXLS_PORTRAIT, $mbottom = 0.98, $mleft=0.78, $mright=0.78, $mtop=0.98, $hmargin=0.5, $fmargin=0.5) FileWriteLine($file, ' </Table>') FileWriteLine($file, ' <WorksheetOptions xmlns="urn:schemas-microsoft-com:office:excel">') FileWriteLine($file, ' <PageSetup>') FileWriteLine($file, ' <Layout x:Orientation="'&$orientation&'"/>') FileWriteLine($file, ' <Header x:Margin="'&$hmargin&'"/>') FileWriteLine($file, ' <Footer x:Margin="'&$fmargin&'"/>') FileWriteLine($file, ' <PageMargins x:Bottom="'&$mbottom&'" x:Left="'&$mleft&'" x:Right="'&$mright&'" x:Top="'&$mtop&'"/>') FileWriteLine($file, ' </PageSetup>') FileWriteLine($file, ' </WorksheetOptions>') FileWriteLine($file, ' <ss:ActiveSheet>Page 2</ss:ActiveSheet>') FileWriteLine($file, ' </Worksheet>') EndFunc ; -------------------------------------------------------------------------------------------------- ; Close Excel workbook, the file now is readable by excel ; -------------------------------------------------------------------------------------------------- Func _XLSCloseWorkBook($file) FileWriteLine($file, '</Workbook>') If Not IsString($file) Then FileClose($file) EndFunc ; ------------------------------------------------------------------------------- ; Create a relative (to $l,$c) formulae to access to $l2,$c2 in sheet $sheet ; ------------------------------------------------------------------------------- Func _XLSlc2rc($l1, $c1, $l2, $C2, $sheet) Local $dc, $dl, $f $dc = $c2-$c1 $dl = $l2-$l1 $f="R" if $sheet <> "" Then $f = $sheet & "!" & $f if $dl<>0 Then $f &= '[' & $dl & ']' $f &= "C" if $dc<>0 Then $f &= '[' & $dc & ']' Return $f EndFunc Abdelrahman 1 Link to comment Share on other sites More sharing options...
wakillon Posted September 2, 2010 Share Posted September 2, 2010 It's look interesting Thanks to share ! AutoIt 3.3.14.2 X86 - SciTE 3.6.0 - WIN 8.1 X64 - Other Example Scripts Link to comment Share on other sites More sharing options...
MishMobile Posted November 18, 2010 Share Posted November 18, 2010 Jerome,I registered so I could let you know that I'm really glad you posted this file.Not needing to install Excel on a web server, but still be able to generate Excel files, has been a huge help.Thanks!Hi all,I'm back with an Excel file generation UDF that can manage multi-sheet workbook but without the need to have Excel installed on the computer...You can add more functions if you want but keep always my name in the post of greetings. Link to comment Share on other sites More sharing options...
jerome Posted November 18, 2010 Author Share Posted November 18, 2010 Hi, It's a long time I have posted this, I even forgot it because of the lack of interrest here... Nice to see it helps. There is a lot of things to enhance in this module... Feel free to modify it and share it back here ! Have a nice day Jerome DERN Link to comment Share on other sites More sharing options...
dmob Posted November 19, 2010 Share Posted November 19, 2010 I also have a need for this functionality, but in another DB langauage I used for a project..... Link to comment Share on other sites More sharing options...
taietel Posted November 19, 2010 Share Posted November 19, 2010 jerome, nice work! I have added a line in your script, Func _XLSCreateWorkbook($file, $activesheet=1) If IsString($file) Then FileDelete($file) $activesheet -= 1 FileWriteLine($file, '<?xml version="1.0"?>') FileWriteLine($file, '<?mso-application progid="Excel.Sheet"?>') ;<<<<<<<<<<<< this line FileWriteLine($file, '<Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet" xmlns:html="http://www.w3.org/TR/REC-html40">') FileWriteLine($file, '<DocumentProperties xmlns="urn:schemas-microsoft-com:office:office"><Author>XLSXMLGenerator</Author><Created>'&@YEAR&'-'&@MON&'-'&@MDAY&'T'&@HOUR&':'&@MIN&':'&@SEC&'</Created><Company>XLSXML</Company></DocumentProperties>') FileWriteLine($file, '<ExcelWorkbook xmlns="urn:schemas-microsoft-com:office:excel"><ActiveSheet>'&$activesheet&'</ActiveSheet></ExcelWorkbook>') EndFunc to avoid the message that appears when using Office2007/2010. Thanks for sharing. M.I. Abdelrahman 1 Things you should know first...In the beginning there was only ONE! And zero... Progs: Create PDF(TXT2PDF,IMG2PDF) 3D Bar Graph DeskGadget Menu INI Photo Mosaic 3D Text Link to comment Share on other sites More sharing options...
muraligupta Posted June 7, 2011 Share Posted June 7, 2011 Hi, I am new to AutoIt. I have a requirement of reading excel files through AutoIt where as Excel is not installed on the machine. Please help me. -murali Link to comment Share on other sites More sharing options...
Maffe811 Posted June 7, 2011 Share Posted June 7, 2011 I belive this is a generation udf, not a reading udf. try reading the helpfile then post some code in the general help and we will try to help. Just writing "I have a requirement... Please help me." is probably not gonna get much interest [font="helvetica, arial, sans-serif"]Hobby graphics artist, using gimp.Automating pc stuff, using AutoIt.Listening to music, using Grooveshark.[/font]Scripts:[spoiler]Simple ScreenshotSaves you alot of trouble when taking a screenshot!Don't remember what happened with this, but aperantly the exe is all i got.If you don't want to run it, simply don't._IsRun UDFIt figures out if the script has ben ran before based on the info in a ini file.If you don't want to use exactly what i wrote, you can use it as inspiration.[/spoiler] Link to comment Share on other sites More sharing options...
muraligupta Posted June 8, 2011 Share Posted June 8, 2011 sorry, i wasn't clear earlier. My intention is to know whether is there any way to read Excel through autoit scripts without excel being installed on that machine. -murali Link to comment Share on other sites More sharing options...
Maffe811 Posted June 8, 2011 Share Posted June 8, 2011 Open the help file and go to User Defined Functions Refrence > Excel Management and see if you can figure it out. Right now it looks like yes you can, but i dont know. [font="helvetica, arial, sans-serif"]Hobby graphics artist, using gimp.Automating pc stuff, using AutoIt.Listening to music, using Grooveshark.[/font]Scripts:[spoiler]Simple ScreenshotSaves you alot of trouble when taking a screenshot!Don't remember what happened with this, but aperantly the exe is all i got.If you don't want to run it, simply don't._IsRun UDFIt figures out if the script has ben ran before based on the info in a ini file.If you don't want to use exactly what i wrote, you can use it as inspiration.[/spoiler] Link to comment Share on other sites More sharing options...
water Posted June 8, 2011 Share Posted June 8, 2011 (edited) sorry, i wasn't clear earlier. My intention is to know whether is there any way to read Excel through autoit scripts without excel being installed on that machine. -murali You can't use the Excel UDF because the UDF relies on the application being installed. The first statement in _ExcelBookOpen is: Local $oExcel = ObjCreate("Excel.Application") But if I remember correctly you can see an Excel file as a database and access it with ADO. Edit: Please check thread or Edited June 8, 2011 by water My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki Link to comment Share on other sites More sharing options...
Maffe811 Posted June 8, 2011 Share Posted June 8, 2011 (edited) Okay, then thats cleared up! I didnt read i just looked at the udf functions. but what is the reason for not installing Excel on the machine ? Edit: I cant click any of thoose things... The link disapeard. Edited June 8, 2011 by Maffe811 [font="helvetica, arial, sans-serif"]Hobby graphics artist, using gimp.Automating pc stuff, using AutoIt.Listening to music, using Grooveshark.[/font]Scripts:[spoiler]Simple ScreenshotSaves you alot of trouble when taking a screenshot!Don't remember what happened with this, but aperantly the exe is all i got.If you don't want to run it, simply don't._IsRun UDFIt figures out if the script has ben ran before based on the info in a ini file.If you don't want to use exactly what i wrote, you can use it as inspiration.[/spoiler] Link to comment Share on other sites More sharing options...
water Posted June 8, 2011 Share Posted June 8, 2011 I have re-inserted the links. Don't know why the were gone. My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki Link to comment Share on other sites More sharing options...
BrewManNH Posted June 8, 2011 Share Posted June 8, 2011 but what is the reason for not installing Excel on the machine ?Might be a server they don't want Office installed on, or a machine in a corporation that is locked down so it can't be installed, they don't want to/can't afford to pay for Excel/Office but need to generate spreadsheets, company machine that's not licensed to use Excel. Those are just off the top of my head. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
Maffe811 Posted June 8, 2011 Share Posted June 8, 2011 Cause i was thinking the problem might have been money and buying MS office, because they could just get open office? [font="helvetica, arial, sans-serif"]Hobby graphics artist, using gimp.Automating pc stuff, using AutoIt.Listening to music, using Grooveshark.[/font]Scripts:[spoiler]Simple ScreenshotSaves you alot of trouble when taking a screenshot!Don't remember what happened with this, but aperantly the exe is all i got.If you don't want to run it, simply don't._IsRun UDFIt figures out if the script has ben ran before based on the info in a ini file.If you don't want to use exactly what i wrote, you can use it as inspiration.[/spoiler] Link to comment Share on other sites More sharing options...
muraligupta Posted June 9, 2011 Share Posted June 9, 2011 Thank you!...i am able to do it with ADO. About Excel not being installed, we have a test environment wherein it should be a clean system without any software installed except the OS. Thanks Once again! Link to comment Share on other sites More sharing options...
hench Posted October 3, 2011 Share Posted October 3, 2011 Great stuff Jerome, thanks for sharing! 5* from me! Link to comment Share on other sites More sharing options...
geometer Posted October 30, 2012 Share Posted October 30, 2012 Hello Jerome, theres a new excel xml udf () Could you combine these 2 UDF to one? Link to comment Share on other sites More sharing options...
Kyan Posted January 29, 2013 Share Posted January 29, 2013 jerome, nice work! I have added a line in your script, Func _XLSCreateWorkbook($file, $activesheet=1) If IsString($file) Then FileDelete($file) $activesheet -= 1 FileWriteLine($file, '<?xml version="1.0"?>') FileWriteLine($file, '<?mso-application progid="Excel.Sheet"?>') ;<<<<<<<<<<<< this line FileWriteLine($file, '<Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet" xmlns:html="http://www.w3.org/TR/REC-html40">') FileWriteLine($file, '<DocumentProperties xmlns="urn:schemas-microsoft-com:office:office"><Author>XLSXMLGenerator</Author><Created>'&@YEAR&'-'&@MON&'-'&@MDAY&'T'&@HOUR&':'&@MIN&':'&@SEC&'</Created><Company>XLSXML</Company></DocumentProperties>') FileWriteLine($file, '<ExcelWorkbook xmlns="urn:schemas-microsoft-com:office:excel"><ActiveSheet>'&$activesheet&'</ActiveSheet></ExcelWorkbook>') EndFunc to avoid the message that appears when using Office2007/2010. Thanks for sharing. M.I. even with the line you had added it stills showing up that error, try to change file extension to xml Heroes, there is no such thing One day I'll discover what IE.au3 has of special for so many users using it.C'mon there's InetRead and WinHTTP, way better Link to comment Share on other sites More sharing options...
MrCreatoR Posted March 21, 2018 Share Posted March 21, 2018 Hi, How do i set "wrap text" for a cell? I can use _XLSSetRowHeight to set fix height, but i want it to be dynamic... Spoiler Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1 AutoIt Russian Community My Work... Spoiler Projects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize ProgramUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF Examples: ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating ) * === My topics === * ================================================== ================================================== AutoIt is simple, subtle, elegant. © AutoIt Team Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now