frank10 Posted October 14, 2020 Posted October 14, 2020 I have to copy an HTML table to an Excel. Like this: https://js.do/code/https-jsfiddle-net-dm7ltq6g-1 I have to copy & paste to preserve also the background colors and formatting bold etc But it has some numbers like "1,200" or "10 / 28" that Excel transforms to 1,2 and ott-28... So I thought to repaste again over the same cells with PasteSpecial only text (it works manually), but I can't get it on Autoit. I use: Local $oTarget = $oWB_KW.Worksheets( "FilterResults") $oTarget.Range("G10").Select $oTarget.Paste $oTarget.PasteSpecial(-4163,Default,Default,Default) Sometimes also Excel sheet crashes with PasteSpecial... Or if you have other ideas as to get the pasted texts correctly formatted...
water Posted October 14, 2020 Posted October 14, 2020 Did you try the _Excel_RangeCopyPaste function of the Excel UDF that comes with AutoIt? It has builtin error handling and tells you what goes wrong by setting @error and @extended. My UDFs and Tutorials: Reveal hidden contents 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
frank10 Posted October 14, 2020 Author Posted October 14, 2020 (edited) I didn't know it could copy from clipboard! good! It works copying from oRange, but I get error from Clipboard: _Excel_RangeCopyPaste($oWB_KW.Worksheets( "FilterResults"), Default , "B10" ) ConsoleWrite(@error & "_ext:" & @extended & @CRLF) 4_ext:-2147352567 Edited October 14, 2020 by frank10
frank10 Posted October 14, 2020 Author Posted October 14, 2020 It works if I put some range from excel sheet to clipboard first with _Excel_RangeCopyPaste($oWB_KW.Activesheet, "A1:S2") and THEN I copy from clipboard to Excel again. But in my case I already have the data on the clipboard (from HTML table) and I must copy them to Excel directly. And I cannot copy them with normal Paste (for the formatting) and then CopyPaste with this func from these cells to copy again with only text because they are already corrupted in the format.
GokAy Posted October 14, 2020 Posted October 14, 2020 (edited) First post, so hello everyone! I may have a solution (or a workaround) depending on how you use the data pasted to Excel. Do you make any calculations with the data? If not, then try the method below (I added the whole script that worked for me with your example HTML table). The step you have missed is the .PasteSpecial("Text") part. While HTML table is in clipboard: #include <Excel.au3> Local $oWB = _excel_Open() _Excel_BookNew($oWB) sleep(2000) $oWB.Activesheet.Range("A1").Select ;Select the appropriate cell in the worksheet you want $oWB.Activesheet.Paste ;Paste as usual $oWB.Selection.NumberFormat = "@" ;The paste method will select the effected cells, which can be referred as "selection". Change number format to "text". $oWB.Selection.PasteSpecial("Text") ;Paste again to the "selection" as PasteSpecial("Text"), maybe "Unicode Text" would work too, haven't tried. Note: You don't need to select cells/range in Excel (while using VBA) to paste stuff unless AutoIt requires it. I have only been using AutoIt for a week now and I haven't used Excel.au3 yet until this post. Hopefully, someone else will correct any inefficient steps in my script. If you need calculations for the pasted data, maybe something else can be managed. Maybe a VBA macro to get things run smooth. I can try help with that side if you want. Edited October 14, 2020 by GokAy frank10 1
frank10 Posted October 14, 2020 Author Posted October 14, 2020 Thank you a lot GokAy! That's exactly what I needed!
frank10 Posted October 14, 2020 Author Posted October 14, 2020 (edited) EDIT It was a problem with the browser... all fine Edited October 14, 2020 by frank10
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