#850 closed Bug (Fixed)
_ExcelReadSheetToArray doesn't work with German Excel 2003
Reported by: | Prog@… | Owned by: | Gary |
---|---|---|---|
Milestone: | 3.3.1.0 | Component: | Standard UDFs |
Version: | 3.3.0.0 | Severity: | None |
Keywords: | Cc: |
Description
In _ExcelReadSheetToArray, the last-cell-string is Split by the character 'R' and 'C' for Row and Column. The problem is, Excel localizes this string, e.g. German: 'Z' (Zeile) instead of 'R' and 'S' (Spalte) instead of 'C'. So, the cell coordinates should be rad with a language-independant StringRegExp:
Local $sLastCell = $oExcel.Application.Selection.SpecialCells($xlCellTypeLastCell).Address(True, True, $xlR1C1) ; Extract integer last row and col $sLastCell = StringRegExp($sLastCell,"\A[^0-9]*(\d+)[^0-9]*(\d+)\Z",3) Local $iLastRow = $sLastCell[0] Local $iLastColumn = $sLastCell[1]
Attachments (0)
Change History (4)
comment:1 Changed 16 years ago by locodarwin@…
comment:2 Changed 16 years ago by Gary
- Milestone set to 3.3.1.0
- Resolution set to Fixed
- Status changed from new to closed
Fixed in version: 3.3.1.0
comment:3 Changed 15 years ago by MrCreatoR <mscreator@…>
Ironicly this fix caused another bug - the docs sais this:
Remarks: If the sheet is empty [0][0] and [0][1] both = 0.
but it's not quite true, here is an example that shows this:
#include <Array.au3> #include <Excel.au3> $oExcel = ObjCreate("Excel.Application") If Not IsObj($oExcel) Then MsgBox(16, "Error: _Exel_Paste", "Couldn't Create Object Excel.Application") EndIf $oExcel = $oExcel.WorkBooks.Add $oExcel.Application.Visible = True For $xlWindow In $oExcel.Windows $xlWindow.Visible = True Next $oExcel.Activate $aLastCell = _ExcelReadSheetToArray($oExcel) _ArrayDisplay($aLastCell, 'Excel') $oExcel.Saved = True $oExcel.Close
To fix it there is need to replace in _ExcelReadSheetToArray UDF this:
; Extract integer last row and col $sLastCell = StringRegExp($sLastCell, "\A[^0-9]*(\d+)[^0-9]*(\d+)\Z", 3) Local $iLastRow = $sLastCell[0] Local $iLastColumn = $sLastCell[1] ; Return 0's if the sheet is blank If $sLastCell = "R1C1" And $oExcel.Activesheet.Cells($iLastRow, $iLastColumn).Value = "" Then Return $avRET
with this:
; Extract integer last row and col Local $aLastCell = StringRegExp($sLastCell, "\A[^0-9]*(\d+)[^0-9]*(\d+)\Z", 3) Local $iLastRow = $aLastCell[0] Local $iLastColumn = $aLastCell[1] ; Return 0's if the sheet is blank If $sLastCell = "R1C1" And $oExcel.Activesheet.Cells(1, 1).Value = "" Then Return $avRET
comment:4 Changed 15 years ago by MrCreatoR <mscreator@…>
One more fix for another bug when the $sLastCell variable includes double info (not sure why), in this form: R120C30:R120C32.
The replace block is now changed to this (regexp changed, and added @error checking)
; Extract integer last row and col Local $aLastCell = StringRegExp($sLastCell, "\A(?:.*:)?[^0-9]*(\d+)[^0-9]*(\d+)\Z", 3) If @error Then Return SetError(4, 0, 0) ;should not happen Local $iLastRow = $aLastCell[0] Local $iLastColumn = $aLastCell[1] ; Return 0's if the sheet is blank If $sLastCell = "R1C1" And $oExcel.Activesheet.Cells(1, 1).Value = "" Then Return $avRET
Guidelines for posting comments:
- You cannot re-open a ticket but you may still leave a comment if you have additional information to add.
- In-depth discussions should take place on the forum.
For more information see the full version of the ticket guidelines here.
Changed the code to submitter's suggestion; nothing breaks, and seems to work as suggested. Recommend updating build with the following replacement function: