I'm trying to teach myself AppleScript on something that I actually need AppleScript for.
(I know there must be shortcuts for something that is repeated but I couldn't find a good tutorial on how to do this, so I did it the long way.)
I'm stuck on how to select multiple columns (or rows) at once. I would like to select the populated columns and sort them but I can't because I don't know how to select multiple columns. Any guidance will be much appreciated.
What I would like the script to do is:
Open an Excel file
Delete rows 1-32
Delete columns 4-7
Delete the new column 7
Select columns 1-5
Sort columns 1-5, first by Task, second by Sample
Delete the rows that include ENDO
Save file
Here is what I have so far:
tell application "Microsoft Excel"
activate
open (choose file)
end tell
tell application "Microsoft Excel"
delete row 1
delete row 1
delete row 1
delete row 1
delete row 1
delete row 1
delete row 1
delete row 1
delete row 1
delete row 1
delete row 1
delete row 1
delete row 1
delete row 1
delete row 1
delete row 1
delete row 1
delete row 1
delete row 1
delete row 1
delete row 1
delete row 1
delete row 1
delete row 1
delete row 1
delete row 1
delete row 1
delete row 1
delete row 1
delete row 1
delete row 1
delete row 1
delete column 4
delete column 4
delete column 4
delete column 4
delete column 7
select row 1
select row 2
end tell
This should get you started: Excel 2004 AppleScript Reference
tell application "Microsoft Excel"
tell active sheet of active workbook
set myRows to range "1:27"
delete myRows
set myColumn to range "D:G"
delete myColumn
end tell
end tell
Related
I have a page on my app that allows the user to create (insert) a new row on my table:
Employee Manager id Status
john ryan 1 Active
angela ryan 2 Active
steve jim 3 Inactive
Id column acting as primary key.
My Interactive Grid is working ok for updates, the 'add row' button works (a new row is displayed and info can be added into it). But when clicking on save, this 'new row added' disappears, info doesn't get inserted into the table at all.
My query as follows:
select
--PK
id,
Manager,
Employee,
--Update only available when Status is active:
decode(Status,'Active', 'U',
'X') as Editable
from my_table
IG attributes:
Edit = enabled
Allowed Operations = update row, add row
Allowed Row Operations Column = Editable
Lost Update Type = row value
Add row if empty = Yes
Anybody has any idea why?
Thank you all
I would like to update all rows inside one column. Each column would have its own input which will update the rest of the rows. Currently I have an existing edit batch table. I was wondeing if it was possible to:
select a column (maybe with checkbox)
Row 1 is empty, however will trigger a function
This function takes the input value (which the user will type) of row 1 cell and populate this value for every row inside the that column.
COL 1 || COL 2
row 1 || row 1
row Z || row Z
After this the user should still be able to activate the cancel button and the original data appears back in the table. The table data should not be saved unless the saved button is pressed.
I've tried a fucntion using a button where we would execute row.set(column, value), however this would refresh the grid table and the original data would reappear.
I have a table:
create table projects(pid int,name char(10),active int);
insert into projects values(1,'aa',1);
insert into projects values(2,'bb',0);
and I want to create a trigger that doesn't allow to delete a project that is active (active=1).
So, for the command:
delete from projects where pid in (1,2)
only row with pid=2 will be deleted and the row with pid=1 will not be deleted.
And no error will be reported (only a warning maybe?).
In SQL Server I am doing it like that:
create trigger nondel on projects instead of DELETE
as
delete from projects where pid in (select pid from deleted where active=0)
end
So "instead of" trigger and only rows that fulfill both delete condition and active=0 condition are deleted.
In Oracle I tried a "for each" trigger:
create trigger nondel before delete on projects
for each row
when :old.active=1
begin
RAISE_APPLICATION_ERROR (-20502, 'Active rows cannot be deleted!');
end
but RAISE_APPLICATION_ERROR aborts the whole transaction and nothing is deleted.
My question is: Is it possible to declare a 'for each row' trigger with a code that when a condition is fulfilled does not not delete the row but doesn't raise any error either, just continues with subsequent rows? Or maybe a statement trigger would be better?
This is totally against the Oracle architecture. It is fine to block an action, as you showed with your RAISE_EXCEPTION trigger, but it is absolutely unusual to suppress an action without an error message.
Theoretically, it could be implemented with an INSTEAD OF trigger, but they work only on views:
create view forcefield as select * from projects;
create or replace trigger tiud_forcefield
instead of insert or update or delete on forcefield
for each row
begin
if INSERTING then
INSERT INTO projects(pid, name, active) VALUES (:new.pid, :new.name, :new.active);
end if;
if UPDATING then
UPDATE projects SET pid=:new.pid, name=:new.name, active=:new.active
WHERE pid = :old.pid;
end if;
if DELETING then
if :old.active = 0 then
DELETE FROM projects WHERE pid = :old.pid;
end if;
end if;
end;
/
The protecting view has all the rows of the table:
select * from forcefield;
PID NAME ACTIVE
1 aa 1
2 bb 0
If you delete an inactive project, it works fine:
delete from forcefield where pid=2;
1 row deleted.
select * from forcefield;
PID NAME ACTIVE
1 aa 1
However, if you try to delete an active project, it still claims that it has deleted one row, but didn't. Yikes!
delete from forcefield where pid=1;
1 row deleted.
select * from forcefield;
PID NAME ACTIVE
1 aa 1
I have a table called Employees with Employee_id and Employee_Name columns. Now i want to create a page with Checkbox in-front of every Employee Name, select the ones that are needed, store them into a temporary table and use them for further operations. The problem i am facing is to how to create that multi select list and store the select values in thee table. Is there an Item for multi select? If not, how should i do it?
There's the Shuttle item. On the left side, you'd display list of all employees. Item buttons allow you to move all (or only some of them) to the right side of the item. Once you submit the page, list of employee IDs is stored into a table column in a form of colon-separated values, for example
6547:8879:5587:9987
This is a simple way of doing that. However, once you have to actually do something with those values, you have to split them to rows. Not a problem, though. Here's a query:
SQL> with emps (shuttle_item) as
2 (select '6547:8879:5587:9987' from dual)
3 select regexp_substr(shuttle_item, '[^:]+', 1, level) one_item
4 from emps
5 connect by level <= regexp_count(shuttle_item, ':') + 1;
ONE_ITEM
---------------------------------------------------------------------
6547
8879
5587
9987
SQL>
Or, you could create a tabular form which also displays all employees and has checkboxes at the beginning of every line. You'd then create a process which - in a loop - stores selected values into a temporary table you mentioned. For example:
-- F01 = row selector. If you check 1st and 3rd row, f01.count = 2 (2 rows checked)
-- f01(1) = 1 (row #1), f01(2) = 3 (row #3)
-- F02 = EMP_ID. f02(1) = EMP_ID that belongs to employee in 1st row,
-- f02(3) = EMP_ID that belongs to emplyee in 3rd row
declare
l_id number;
begin
for j in 1 .. apex_application.g_f01.count
loop
l_id := apex_application.g_f02(apex_application.g_f01(j));
insert into temp_table (emp_id) values (l_id);
end loop;
end;
There is an option for creating multi select list in oracle apex 5.1.
Create a pageItem of type: 'select list'.
Make the 'Allow multi
selection' to 'Yes'.
Write the SQL query for your select list under
the 'List of Values' attribute.
Then the select list will be
displayed based on our query.
Query format is:
select [displayValue],
[returnValue]
from ...
where ...
order by ...
Now once you select multiple value from select list(using ctrl+click), these are stored as ':' separated values in the select list page item.
I've created a video some times ago that covers your problem. It's a step by step tutorial how to create checkboxes and process them.
Video is available here:
https://www.youtube.com/watch?v=T-LXRMWQbPk
Regards
If the list is too big, I recommend to use the Popup LOV item with the Multiple Values switch activated instead the Select list or the Shuttle, because it has an internal search field for the objects list, doing way easier for the user to find the target values. Also, just as the Select List or Shuttle item, you can set a Separator character for the selected fields.
I have table table_name with PK(id1 VARCHAR2(10), id2 NUMBER, id3 NUMBER)
This table only grow ~ 1 million records each year.
The problem is that in procedure A, I must DELETE 1 row in table_name if exists.
Procedure A is run very frequently by many users. The number of actual deletes (delete an existing row) is very small compared to the number of times procedure A will try to delete a row.
So what is better performance-wise: just delete the row (solution 1) , or check if exists then delete it (solution 2)?
What about row lock for each solution? Will DELETE lock table row in transaction of proc A if row does not exists?
Solution 1
DELETE table_name
WHERE id1 = p_id1
AND id2 = p_id2
AND id3 = p_id3;
Solution 2
SELECT COUNT(*) INTO l_check_exists
FROM table_name
WHERE id1 = p_id1
AND id2 = p_id2
AND id3 = p_id3;
IF l_check_exists <> 0
THEN
DELETE table_name
WHERE id1 = p_id1
AND id2 = p_id2
AND id3 = p_id3;
END IF;
Just delete the row. To delete it, Oracle first has to find it, which is essentially the same as performing a select statement (but without returning data). If Oracle doesn't find it, it won't delete it of course. There is no scenario in which checking first yourself via a SELECT statement will be quicker.
Also, if a record does not exist, it cannot be locked either, obviously.
Oracle cannot lock row if row does not exist. It just don't know how to do it :)
In worst scenario second solution is twice longer, but it try to success ratio is as small as you said, I guess, it would be equal performance in both cases.