Ebola57 Posted September 4, 2020 Share Posted September 4, 2020 (edited) Hi Community I am intending to read only the filtered cells of a sheet At a second stage I have to write back in this sheet, so I need to store somewhere (why not in outputed array from _Excel_RangeRead ) May you help me to proceed Such code does not give me a way to identify the index to write back if I am write #include <Excel.au3> $oExcel = _Excel_Open ( False, False, False, True ) $oWorkbook = _Excel_BookOpen ( $oExcel, "Myfile" ) $oRange = $oWorkbook.ActiveSheet.Usedrange.SpecialCells($xlCellTypeVisible) Local $aResult[1][$oRange.Columns.Count], $aContent ; Read the data of all Ranges in the Area and concatenate the returned arrays. For $oArea In $oRange.Areas $aContent = _Excel_RangeRead($oWorkbook, Default, $oArea) _ArrayConcatenate($aResult, $aContent) Next _ArrayDisplay($aResult) Regards Edited September 4, 2020 by Ebola57 Link to comment Share on other sites More sharing options...
water Posted September 4, 2020 Share Posted September 4, 2020 A member of the Areas collection is a Range object. You could use the Address property to retrieve the address of the upper left cell in this Range and then the .Columns.Count and .Rows.Count properties for the Area to retrieve the number of columns and rows to calculate the other addresses. Ebola57 1 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...
Nine Posted September 4, 2020 Share Posted September 4, 2020 Here the approach I would use. Instead of creating a single 2D array containing all the values of all the areas, I suggest you store the range object into the first column of an array, and the second column would contain its corresponding matrix. That way you can have different size of area. You can modify each matrix individually and rewrite them into the excel sheet easily by using its range object. #include <Excel.au3> $oExcel = _Excel_Open() $oWorkBook = _Excel_BookAttach("65000.xls","FileName") $oRange = $oWorkbook.ActiveSheet.range("A1:B5;C10:E15;D20:G30") $oRange.select Local $aResult[$oRange.Areas.count][2], $i = 0 For $oArea In $oRange.Areas ConsoleWrite ("Area " & $i & " = " & $oArea.rows.count & "/" & $oArea.columns.count & @CRLF) $aResult[$i][0] = $oArea $aResult[$i][1] = _Excel_RangeRead($oWorkbook, Default, $oArea) _ArrayDisplay($aResult[$i][1]) $i += 1 Next ; Make some modifications to the areas ; Example : Double the values of first column Local $aTmp For $i = 0 to UBound($aResult)-1 $aTmp = $aResult[$i][1] For $j = 0 to UBound($aTmp)-1 $aTmp[$j][0] *= 2 Next _Excel_RangeWrite($oWorkBook, Default, $aTmp, $aResult[$i][0]) Next Ebola57 1 “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...
Ebola57 Posted September 24, 2020 Author Share Posted September 24, 2020 (edited) Thanks for your help, it helps me a lot This is code I wrote to get what I need. I catch data from Excel, add a column where line appears then filter the lines I need By the way, I touch as few the Excel file as possible ( I need it to be fast ) $oUsed_Range = $oWorkbook.ActiveSheet.UsedRange $aData_Used_Range = _Excel_RangeRead ( $oWorkbook, Default, $oUsed_Range ) _ArrayColInsert ( $aData_Used_Range, 0 ) $aData_Used_Range [0] [0] = "Index" For $iLine = 1 To UBound ( $aData_Used_Range) - 1 $aData_Used_Range [$iLine] [0] = $iLine + 1 Next $Nb_of_Columns = $oWorkbook.ActiveSheet.Usedrange.Columns.Count $oVisible_Ranges = $oWorkbook.ActiveSheet.Usedrange.SpecialCells ( $xlCellTypeVisible ) Local $aData_Visible_Range [0] [$Nb_of_Columns] For $oVisible_Range In $oVisible_Ranges.Areas $aContent = _Excel_RangeRead ( $oWorkbook, Default, $oVisible_Range ) _ArrayConcatenate ( $aData_Visible_Range, $aContent ) Next _ArrayColInsert ( $aData_Visible_Range, 0 ) $aData_Visible_Range [0] [0] = "Index" For $iLine = 1 To UBound ( $aData_Visible_Range) - 1 Local $iFound = _ArraySearch ( $aData_Used_Range, $aData_Visible_Range [$iLine] [1], 1, Default, Default, Default, Default, 1 ) If Not @error Then $aData_Visible_Range [$iLine] [0] = $aData_Used_Range [$iFound] [0] Next Edited September 24, 2020 by Ebola57 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