Livecode Datagrid Copy and Paste - livecode

Using the livecode datagrid, does copy and paste from one cell to another possible? Something like the spreadsheet capability.
Currently, we need to double click the cell and copy its text from one cell to another non-empty cell.
Update: This is now working. I got below code from here
on commandKeyDown k
switch k
case "c"
copy
break
case "v"
paste
break
default
pass commandKeyDown
end switch
end commandKeyDown

Yes, if cell editing is enabled, you will find that a DataGrid acts very much like a spreadsheet. Just pretend you are in Excel, and use the DataGrid the same way. So if you copy some portion of data in a "cell", you may set the insertion point at any point in any other "cell". Then just paste as usual.
This is all doable under script control, where you can extract the contents of the DataGrid via the dgText or the dgData, manipulate that data in the clear or as an array, and then reset that property with the new information.

Related

Use common dropdown across multiple worksheets to change single cell

I have a large file with a Scenario Manager, where changing a single cell on the Summary worksheet changes the visible scenario throughout the rest of the workbook. Data Tables are working a treat providing the headline values for each option.
I'd like to have a drop down on each sheet that when changed will change the same single cell on the Summary worksheet, so I don't need to go back to the Summary sheet every time I want to switch visible scenarios.
This is a simple process if I'm using macros and would be the solution I'd normally jump straight to. But this needs to be done without macros and this is where I'm now struggling.
Does anyone know if this is possible (without macros) and point me in the right direction?
Josh
You can insert combo box (Developer Tab > Insert > Form Controls > Combo Box) on each sheet. Mention linked cell as a cell of the summary sheet (Absolute reference with sheet name). That cell will give you index of the item selected in the drop down list. Then you can insert index formula in the cell you want to change every time to get value of the drop down list. Once you insert it on one sheet you can copy it to other sheets. No macros required.

Copy cells from excel sheet and paste it to a DB query Sikuli

I am new to Sikuli. I need to copy data from excel sheets and paste them to a DB query using sikuli script. And how can I iterate among the excel cells to copy and paste the data repeatedly.
These data needs to copied and pasted one after the other.
It might be easier to copy all of the cells at once, then paste them one by one.
once Sikuli has opened Excel, you could do something like:
type(Key.HOME, KeyModifier.CTRL) #takes you to cell A1
type("a", KeyModifier.CTRL) #select all
type("c", KeyModifier.CTRL) #copy to clipboard
fromExcel = Env.GetClipboard().strip() #get clipboard contents into Sikuli, without leading or trailing white space
cells = fromExcel.split("/n") #split each cell into list on newline
#go to the destination app, maybe using App.open("nameOfYourApp") if it's not open yet, or App.focus("nameOfYourApp") if it is already open
for cell in cells: #use python to iterate through your list
#navigate to the line or cell where you want to paste
paste(cell)
Would something like that be of help?
Rather than providing a specific approach let's understand the options you have.
Simulate user keyboard actions (like it is described here by #autoKarma).
Excel sheet having a very specific structure allows you to detect some key points like first column and first row and then calculate other cells locations based on them.
You can try and use one of the Python Excel API libraries to access the excel sheet directly via API. If you only need to read the document and to to amend it, I believe this will be fairly easy to do.
Note: In all cases you will obviously have to think of how do you bring yourself to the point where you have an open Excel sheet on your screen and how to dispose of it when done.

Transform data calculated via formulas into static values

The way I have been using excel to transform data calculated via formulas into static values was to select each cell, press F2 to edit it and then press F9to replace the content of that cell with the result of the formula in it.
I was wondering if there is a convenient way to do this process to a group of selected cells. It would come in handy if I wanted to do this to hundreds of cells at a time.
Could anybody please tell me if that is possible? And if so, how?
If a VBA based solution is viable, then this short routine should suffice.
sub Values_Only()
with selection
.value = .value
end with
end sub
Just select a group of cells and tap Alt+F8 then Run the macro. Optionally, use Options in the Macros dialog to set a hot key combination.
You may also find the Quick Access Toolbar (aka QAT) of use to assign the Paste Values command to a hotkey. Mine is set to Alt+2. With any group of cells selected, Ctrl+C then Alt+2 is sufficient to revert formulas to their returned values. See this for more information.
Highlight all of the desired cells. Copy them. Then right click the highlighted area and select the 123 paste option.

Auto populate column by reference?

I am working on the following sheet, called Raw_Data:
In a new sheet, I want to copy the registration_date column by reference. This means that if I change the registration_date on the Raw_Data, the changed value should be reflected in the new sheet.
To implement this, I have entered the following =Raw_Data!C2. So far it works fine as you can see below:
But the problem is that when I double click on the little green square here, it doesn't automatically populate the entire column.
I don't want to manually drag-and-drop because there are several thousand rows. Does anyone know how I could automatically populate the column by reference?
While there are some automation things you could do, I think a lot of that would be overkill for what could be just an input issue with how you are choosing to copy in Excel.
If you find that you need to copy a large block of data, rather than dragging the corner of your cell like that, try one of these alternate methods:
While selected on the cell, press CNTRL + C. Then in the 'Name Box' (where it shows the address of the cell you are on), type in the cell where you want to go (A17000); then press SHIFT + ENTER. This will jump you to that cell, and will highlight all cells inbetween where you were and where you are going. Then press CNTRL + V.
Another method of moving around a large data block in Excel is to hold CNTRL and press an arrow key. This will move you as far down the data block as possible. Note that this will not work on a blank sheet, as there is no data and therefore Excel doesn't know when to stop.
Again - some automation would be possible here, but moving around an Excel worksheet is something you will be doing too frequently in too many different ways to want to automate what might be 5 keystrokes once a week.
In excel the "double click to fill" feature is a heuristic based feature that fills the cells that appear to be relevant with the selected formula (+ reference corrections).
In your case there is no hint the heuristic can use to tell what to fill so nothing is being done.
Regarding dragging "several thousand rows", that's not a real problem. If you only do it once, there no reason to even trying anything "smart" or complicated.
You can also copy the source cell, select all the cells you want to fill and then paste. You can select cells in any way you like, not just dragging.
You could instead of all the dragging/copying/filling approach simply copy directly from the source, and paste by reference.
As a last resort, you can always go for a VBA solution to do that for you.

How do you place a textbox object over a specific Cell when automating Excel?

We are automating Excel using VB.Net, and trying to place multiple lines of text on an Excel worksheet that we can set to not print. Between these we would have printable reports.
We can do this if we add textbox objects, and set the print object setting to false. (If you have another way, please direct me)
The code to add a textbox is:
ActiveSheet.Shapes.AddTextbox(msoTextOrientationHorizontal, 145.5, 227.25, 304.5, 21#)
but the positioning is in points. We need a way to place it over a specific cell, and size it with the cell. How can we find out where to put it when we just know which cell to put it over?
If you have the cell name or position, you can do:
With ActiveSheet
.Shapes.AddTextbox msoTextOrientationHorizontal, .Cells(3,2).Left, .Cells(3,2).Top, .Cells(3,2).Width, .Cells(3,2).Height
End With
This will add a textbox over cell B3. When B3 is resized, the textbox is also.
When you copy & paste a textbox, Excel will place the new textbox over whichever cell is currently selected. So you can achieve this very easily by simply using the VBA copy & paste commands. This can be particularly useful if you are going to be using a lot of very similar textboxes, as you are effectively creating a textbox template.

Resources