Sign in to follow this  
Followers 0
Jockem

.xlsx to .cfg?

10 posts in this topic

Is it possible to use autoit to convert a .xlsx file to a .cfg file?

Share this post


Link to post
Share on other sites



Yes. Open the the spreadsheet using Excel.au3 UDF, read data, then write data (config files are normally text files, so FileOpen+FileWrite+FileFlush as normal)

Could you give an example of the spreadsheet content and what the config file looks like? 

Share this post


Link to post
Share on other sites

This is my script,It now opens PDF but i can't make it open Cfg.

#include <Excel.au3>
#include <MsgBoxConstants.au3>
 
 
 
Local $oAppl = _Excel_Open()
If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_Export Example", "Error creating the Excel application object." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
Local $oWorkbook = _Excel_BookOpen($oAppl, "C:testnagiosscriptnagios logs.cfg" , True)
If @error Then
    MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_Export Example", "Error opening workbook '" & "C:testnagiosscriptnagios.xlsx" & @CRLF & "@error = " & @error & ", @extended = " & @extended)
    _Excel_Close($oAppl)
    Exit
EndIf
 
Local $sOutput = "C:testnagiosscriptnagios.xlsx"
_Excel_Export($oAppl, "A1:E6", $sOutput, Default, Default, Default, Default, Default, True)
If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_Export Example 1", "Error saving range to '" & $sOutput & "'." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_Export Example 1", "Range successfully exported as '" & $sOutput & "'.")

Share this post


Link to post
Share on other sites

Why are you trying to open the Nagios log with Excel? Can you please post the log to this thread, so we can see what you're trying to do? I've done conversion of their log files before, but only with Perl, and never with Excel.


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

I am doing a project for a college, he supplied the information in an Excel file but he wants a script wich reads excel and writes away as a cfg file. 

I got my information in an excel sheet, i need to convert this to a cfg file, i just dont know how and in the extract function it only allows you to choose pdf or xps so thats not it but i coudnt find anything els to convert it to a cfg file.

Share this post


Link to post
Share on other sites

You coul use _Excel_BookSaveAs to save the workbook as text.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

if i do that i copy a piece of the help function but i dont know what variable to put at $xlhtml because it doesnt specify anthing, please help me

_Excel_BookSaveAs($oWorkbook, $sWorkbook, $xlHtml)

Edited by Jockem

Share this post


Link to post
Share on other sites

The excel conststants file has all the file types which can be found here (copied from the ExcelConstants.au3 file):

These are the text ones that may interest you.

Global Const $xlTextMSDOS = 21 ; MSDOS Text
Global Const $xlTextPrinter = 36 ; Printer Text
Global Const $xlTextWindows = 20 ; Windows Text
Global Const $xlUnicodeText = 42 ; Unicode Text

Build your own poker game with AutoIt: pokerlogic.au3 | Learn To Program Using FREE Tools with AutoIt

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

Thanks for the tip but now if i run the script i dont get a fault message, so i got that going for me wich is nice but also nothing happens...

What do i miss???

_Excel_BookSaveAs ( "C:testnagiosscriptnagios.xlsx", "C:testnagiosscriptnagios.txt", $xlTextWindows )

Could some one post an example please, im really stuck  :wacko:

Edited by Jockem

Share this post


Link to post
Share on other sites

I fixed it, thanks for the help guys!   :sorcerer:

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0