DougK Posted March 11, 2022 Share Posted March 11, 2022 I wrote an application that reads a User's full name, their Employee number, where they work and a Date/Time, which is written to an SQL Database, This works great, now I am working on another app that reads the SQL database into a 2DArray. This part of it appears to be working. Then I am using the _Excel_BookNew($oExcel) to send the data to the array and then to an Excel Spreadsheet. This is working with the exception of the date/Time field. Below are some screenshots of what I am seeing; This is from the SQL Database - This is the 2D Array. I think this is where the issue is. - And this is what I see in Excel - I don't/ know if it is my database insertion of Date/Time, or it is the conversion from Array to Excel. This is my code for insertion into the database with the line creating the variable for Date/Time; Local $datetime = _DateTimeFormat(_NowCalc(), 0) local $RecAdd =_SQL_Execute(-1,"INSERT INTO dbo.Work_Location (Zone,FullName,EmployeeID,WorkLocation,Date) VALUES ('" & $Zone & "' ,'" & $FullName & "' ,'" & $EmpID & "' ,'Office','" & $datetime & "');") Here is my code to read the database into the 2DArray and then export to Excel. Local $aData,$iRows,$iColumns;Variables to store the array data in to and the row count and the column count $GetDB = _SQL_GetTable2D(-1,"SELECT * FROM dbo.Work_Location;",$aData,$iRows,$iColumns) If $GetDB = $SQL_OK then _arrayDisplay($aData,"2D (" & $iRows & " Rows) (" & $iColumns & " Columns)" ) $oExcel = _Excel_Open(False) $oBook = _Excel_BookNew($oExcel) _Excel_RangeWrite($oBook,Default,$aData) _Excel_BookSaveAs($oBook,@ScriptDir & '\test5.xlsx',$xlOpenXMLWorkbook) _Excel_Close($oExcel) Anyone have any thoughts on this? Thank you in advance for your assistance. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted March 11, 2022 Moderators Share Posted March 11, 2022 Moved to the appropriate AutoIt General Help and Support forum, as the Developer General Discussion forum very clearly states: Quote General development and scripting discussions. Do not create AutoIt-related topics here, use the AutoIt General Help and Support or AutoIt Technical Discussion forums. Moderation Team Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
seadoggie01 Posted March 11, 2022 Share Posted March 11, 2022 You'll need to add the formatting back before you write to Excel. The format you can see in your database works for excel as well. Right now, it looks to excel like you're entering a very large number because there's no date separation. You can either find a way that reading from the database returns the format to AutoIt or you can fix it in AutoIt with a series of StringSplits on each row of data All my code provided is Public Domain... but it may not work. Use it, change it, break it, whatever you want. Spoiler My Humble Contributions:Personal Function Documentation - A personal HelpFile for your functionsAcro.au3 UDF - Automating Acrobat ProToDo Finder - Find #ToDo: lines in your scriptsUI-SimpleWrappers UDF - Use UI Automation more Simply-erKeePass UDF - Automate KeePass, a password managerInputBoxes - Simple Input boxes for various variable types Link to comment Share on other sites More sharing options...
Nine Posted March 11, 2022 Share Posted March 11, 2022 (edited) Maybe this : #include <Excel.au3> Local $aData = [[1, "Douglas", 12345, "Office", 20220311140853]] Local $oExcel = _Excel_Open() Local $oBook = _Excel_BookNew($oExcel) $aData[0][4] = StringRegExpReplace(String($aData[0][4]),"(.{4})(.{2})(.{2})(.{2})(.{2})(.{2})","$1-$2-$3 $4:$5:$6") $oBook.Activesheet.Columns("E").ColumnWidth = 20 $oBook.Activesheet.Columns("E").NumberFormat = "yyyy-mm-dd hh:mm:ss" _Excel_RangeWrite($oBook,Default,$aData) Edited March 11, 2022 by Nine “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
water Posted March 11, 2022 Share Posted March 11, 2022 More details about formatting an Excel Range can be found in the wiki. My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki 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