Mian Posted December 17, 2015 Posted December 17, 2015 Hi, I am new to AutoIT but I have many years of IT experience. I searched a lot for saving the document as xls and xlsx file but no success. The following is my code. Please help.#include <Excel.au3>Global $oExcel="D:\ChromeDownloads\abc.csv"$prog_excel = _Excel_Open() ;opens a new instance of the Excel softwaresleep(5000)$workbook = _Excel_BookOpen($prog_excel, $oExcel) ; open an existing excel file$oExcel.ActiveWorkbook.SaveAs ( "D:\ChromeDownloads\abc.xlsx",50,"","",False,False);_Excel_BookSaveAs($oExcel, "D:\ChromeDownloads\abc", "xlWorkbookDefault", True);_Excel_BookClose($oExcel, 1, 0) ;This method will save then Close the file, without any of the normal prompts, regardless of changes
UEZ Posted December 17, 2015 Posted December 17, 2015 (edited) Try_Excel_BookOpenTextto open CSV. Edited December 17, 2015 by UEZ Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ
water Posted December 17, 2015 Posted December 17, 2015 You need to add some error checking. What is the value of @error after _Excel_BookOpen or _Excel_BookSaveAs? 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
Mian Posted December 21, 2015 Author Posted December 21, 2015 (edited) Hi my question is how can I save a file as xls type. For example at the moment I am using the following code which is saving a file as an xls format after it is modified in excel.; Script to save document. send("{f12}") ; this code open the save as dialog box in excel sleep(3000) Send("{TAB 1}"); this code select the save as type option sleep(3000) Send("M") ; this code select the type as xls format sleep(3000) Send("{TAB 6}"); this code click the save button Send("S") ; this code click the save button sleep(3000) WinWait('Confirm Save As') ; this code wait until the confirmation pop up appears WinActivate('Confirm Save As') ; this code activate the save as pop up Send("{TAB 1}") ; this code select the yes button Send("{ENTER}") ; this code click the save button to overwrite the previously saved file. Edited December 21, 2015 by Mian
water Posted December 21, 2015 Posted December 21, 2015 If you could post an (anonymized) part of your CSV (just a few lines) I'm sure I can come up with a simple script to open the CSV and save it as XLSX. 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
Mian Posted December 21, 2015 Author Posted December 21, 2015 If you could post an (anonymized) part of your CSV (just a few lines) I'm sure I can come up with a simple script to open the CSV and save it as XLSX.Thank you @water for your quick reply. The file I am working is a long file of more than 200 columns but any csv will do. In fact it doesnt matter that what file I am opening. All I need is to save a file opened in excel as excel file. But for you I am adding the sample csv I downloaded from https://support.spatialkey.com/spatialkey-sample-csv-data/ FL_insurance_sample.csv
water Posted December 21, 2015 Posted December 21, 2015 Rename your CSV file to TXT and the following code will work: #include <excel.au3> #include <MsgBoxConstants.au3> Global $sPathTXT = "C:\temp\FL_insurance_sample.txt" Global $sPathExcel = "C:\temp\FL_insurance_sample.xlsx" Global $oExcel = _Excel_Open() If @error Then Exit MsgBox($MB_ICONERROR, "ERROR", "Error creating the Excel application object." & @CRLF & "@error = " & @error & ", @extended = " & @extended) Global $oWorkbook = _Excel_BookOpenText($oExcel, $sPathTXT) If @error Then Exit MsgBox($MB_ICONERROR, "ERROR", "Error creating the new workbook." & @CRLF & "@error = " & @error & ", @extended = " & @extended) _Excel_BookSaveAs($oWorkbook, $sPathExcel) If @error Then Exit MsgBox($MB_ICONERROR, "ERROR", "Error saving the workbook." & @CRLF & "@error = " & @error & ", @extended = " & @extended) 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
philipyo Posted February 20, 2017 Posted February 20, 2017 https://support.office.com/en-us/article/Import-or-export-text-txt-or-csv-files-5250ac4c-663c-47ce-937b-339e391393ba
steveeye Posted May 23, 2017 Posted May 23, 2017 On 12/21/2015 at 9:30 PM, water said: Rename your CSV file to TXT and the following code will work: #include <excel.au3> #include <MsgBoxConstants.au3> Global $sPathTXT = "C:\temp\FL_insurance_sample.txt" Global $sPathExcel = "C:\temp\FL_insurance_sample.xlsx" Global $oExcel = _Excel_Open() If @error Then Exit MsgBox($MB_ICONERROR, "ERROR", "Error creating the Excel application object." & @CRLF & "@error = " & @error & ", @extended = " & @extended) Global $oWorkbook = _Excel_BookOpenText($oExcel, $sPathTXT) If @error Then Exit MsgBox($MB_ICONERROR, "ERROR", "Error creating the new workbook." & @CRLF & "@error = " & @error & ", @extended = " & @extended) _Excel_BookSaveAs($oWorkbook, $sPathExcel) If @error Then Exit MsgBox($MB_ICONERROR, "ERROR", "Error saving the workbook." & @CRLF & "@error = " & @error & ", @extended = " & @extended) This one worked for me. I got more issues that I am facing can I ask them to you 'water'.
water Posted May 23, 2017 Posted May 23, 2017 Sure. Simply post them here if they are related to the subject of this thread or open a new one. 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
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