Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Simple (I hope) Cut and Paste from Text File to Excel.
#1
Greetings.  I'm having great difficulty doing something I think should be simple, so I must be missing something.

I'm using a program that produces text reports inside the app.  I am able to manually Ctl A / Ctl C the report and then Ctl V into a cell (H1) in Excel.  The report loads with each line in a new row, which is what I need to process the information.  I've tried many, many things but can't get it to work in QM.  I am trying to accomplish this without using mouse clicks in Excel since I won't be able to rely on the xy coordinates for the target cell remaining constant. Here is my code snippet, with comments:
Quote: opt slowkeys; spe 1000ExcelSheet esWorkTab.Init("WorkTab")
int w=wait(1 WV win("TestApp" "HwndWrapper[TestApp.exe;*"))
str views

 ;; Copy the Report
lef 658 166 w 1
'Ca
views.getsel

 ;; Paste clipboard to cell H1 of WorkTab. (Have tried the following):
;; esWorkTab.SetCell(views "H1") ;; Puts entire report in H1 (well, not even the entire report)
;; esWorkTab.SetCell(views "H") ;; Produces: Error (RT) in <open ":1546: /314">Test Cut Paste:  0x80020009, Exception occurred. 0x3EC,. <help #IDP_ERR>  (although Help shows this as a valid option??)
;; esWorkTab.SetCell(views 8) ;; Produces: Error (RT) in <open ":1546: /471">Test Cut Paste:  invalid index, must be >=1.
;; esWorkTab.SetCell(views "H:H") ;; Produces: Error (RT) in <open ":1546: /314">Test Cut Paste:  0x80020009, Exception occurred. 0x3EC,. <help #IDP_ERR>

 ;; Have also tried various combinations of getclip, setclip, getsel and setsel, but could not get output to H1.

 ;; Have also tried A{hvt}, but that seems to require a mouse click in cell H1, which I don't really want to do, as I can't rely on its xy location over time.   esWorkTab.Activate and esWorkTab.SetCell("H1") wasn't enough to allow the A{hvt} to work.


Can you please let me know how to accomplish this?

EDIT:  1. Please see better pasted code below.
          2. Above, I said "The report loads with each line in a new row …".  Actually, it loads each Paragraph in a new row, or perhaps, paragraphs and/or sentences separated by CR/LF?  That's in manual operation, which I'd like to duplicate in QM without requiring xy clicks in Excel.
#2
opt slowkeys; spe 1000
ExcelSheet esWorkTab.Init("WorkTab")
int w=wait(1 WV win("TestApp" "HwndWrapper[TestApp.exe;*"))
str views

;; Copy the Report
lef 658 166 w 1
'Ca
views.getsel

;; Paste selection to cell H1 of WorkTab. (Have tried the following):
esWorkTab.SetCell(views "H1") ;; Puts entire string in H1 (well, not even the entire report)
esWorkTab.SetCell(views "H") ;; Produces: Error (RT) in <open ":1546: /314">Test Cut Paste:  0x80020009, Exception occurred. 0x3EC,. <help #IDP_ERR>
esWorkTab.SetCell(views 8) ;; Produces: Error (RT) in <open ":1546: /471">Test Cut Paste:  invalid index, must be >=1.
esWorkTab.SetCell(views "H:H") ;; Produces: Error (RT) in <open ":1546: /314">Test Cut Paste:  0x80020009, Exception occurred. 0x3EC,. <help #IDP_ERR>

;; Have also tried various combinations of getclip, setclip, getsel and setsel, but could not get output to H1.

;; Have also tried A{hvt}, but that seems to require a mouse click in cell H1, which I don't really want to do, as I can't rely on its xy location over time.
   esWorkTab.Activate and esWorkTab.SetCell("H1") wouldn't allow the A{hvt} to work.
#3
try this
Code:
Copy      Help
opt slowkeys; spe 1000
ExcelSheet esWorkTab.Init("WorkTab")
int w=wait(1 WV win("TestApp" "HwndWrapper[TestApp.exe;*"))
str views

;;;Copy the Report
lef 658 166 w 1
'Ca
views.getsel

;;;Paste selection to cell H1 of WorkTab.
esWorkTab.SelectCell("H1")
esWorkTab.Activate(4)
1
key A{hvt} ;;works, pastes
#4
Thank you Kevin!

I'm embarrassed to say how many hours I spent trying to get this to work, so I won't.  I had tried that exact code, except that I only tried the 0 and 1 flags on the Activate method.  I thought activating the worksheet was what I needed.  I never tried the 4 flag.  Do you know why activating the worksheet isn't sufficient?

At any rate, I'm a very happy camper.  Thanks again.
#5
Question 
Quote:Do you know why activating the worksheet isn't sufficient?

from ExcelSheet.Activate help

Remarks
Activating a sheet/book does not mean activating Excel window. It just brings the sheet/book on top of other sheets/books. To activate Excel window, use flag 4.


Forum Jump:


Users browsing this thread: 1 Guest(s)