Is it possible to format both a row and column?
For instance I am doing a loop that uses the index to style rows different colors based on if it is even or odd but I also want to style a column that has percentages to use the :num_fmt => 9
Also why when I am presenting the number as something like 1.2 does that end up changing it to 120%, all I want is for that data to look like 1.2%
#people.each_with_index | person, index |
if index.odd?
sheet.add_row [person['name'], person['rate']]
else
sheet.add_row [person['name'],person['rate']], :style => even_row
end
end
(my even row style is set at the top of my code)
I figured this out, you need to do set your style using something like
percent = s.add_style(:num_fmt => 9)
even_row_percent = s.add_style(:bg_color => 'blue', :fg_color => 'white', :b => false, :format_code => 0%)
even_row = s.add_style(:bg_color => 'blue', :fg_color =>'white', :b => false)
then in your loop just use an each with index and then use a if statement like
if index.odd
sheet.add_row[
item[:value],
item[:value_percent]], :style => [nil, percent]
else
sheet.add_row[
item[:value],
item[:value]], :style => [even_row, even_row_percent]
end
Related
I have a Classic Report with a schedule for each day. There are no, one or multiple entries per day. It looks like this:
select
week_no,
apex_item.DISPLAY_AND_SAVE(p_idx => 8, p_value => plan_id) as ID,
apex_item.select_list(p_idx => 1, p_list_values => 'S1;1,S2;2,S3;3', p_attributes => 'size="3" multiple="multiple"', p_show_null => 'NO', p_show_extra => 'NO', p_item_id => plan_id || '_1', p_value => monday) as monday,
apex_item.select_list(p_idx => 2, p_list_values => 'S1;1,S2;2,S3;3', p_attributes => 'size="3" multiple="multiple"', p_show_null => 'NO', p_show_extra => 'NO', p_item_id => plan_id || '_2', p_value => tuesday) as tuesday,
apex_item.select_list(p_idx => 3, p_list_values => 'S1;1,S2;2,S3;3', p_attributes => 'size="3" multiple="multiple"', p_show_null => 'NO', p_show_extra => 'NO', p_item_id => plan_id || '_3', p_value => wednesday) as wednesday
from plan;
I can select multiple values and can save them to my table. It gets save like this "1,2". But I can't load the data rows with multiple selected values.
I can select multiple options with jQuery like this
$('#1000_1').val(["1","2"]);
but I don't know how to select the stored values from table with PL/SQL and then set the options selected with javascript.
I tried to load the data in an apex_item.text (id="1000_11" for monday etc.) and transfer the values in "After Refresh" DA to select list like that:
var sel_opt = $('#1000_11').val();
if (sel_opt == "1,2")
{
$('#1000_1').val(["1","2"]);
}
else if (sel_opt == "1,3")
{
$('#1000_1').val(["1","3"]);
}
else if (sel_opt == "2,3")
{
$('#1000_1').val(["2","3"]);
}
else if (sel_opt == "1,2,3")
{
$('#1000_1').val(["1","2","3"]);
}
It works, but maybe there's a smarter solution?
I create a sample Workspace on https://apex.oracle.com/pls/apex/f?p=4550:1:0:::::
Workspace: multi_select
Username: dev
Password: newYears3problems
I would create SELECT LIST page items for each selection menu and set their multi selection option to Yes.
then I'm guessing I'd need something like this somewhere at my page-process section
declare
array apex_application_global.vc_arr2;
begin
array := apex_util.string_to_table (:P30_SELECT_LIST_1);
apex_collection.create_or_truncate_collection ('P30_SELECT_LIST_1');
apex_collection.add_members ('P30_SELECT_LIST_1', array);
end;
to store more than one menu item at once.
then I'd add something like that to my query
and ITEM_1 in (
select c001
from apex_collections
where collection_name = 'P30_SELECT_LIST_1'
)
I probably didn't understand your question, but according to part that I get, it's straightforward sql query. no need for js.
I have a interactive grid with column email_to email_from which is editable grid, now i need to fetch the values which we are entering into columns in grid..my items are :p1_email_to,:p1_email_from..
below is my query which is calling the email procedure, here i need to pass the item values which i am entering on screen but the item values are showing null, the grid values are not returning to items.
Here the query for on submit button:
DECLARE
p_division EMAIL_ERRORS.ORG_ID%TYPE;
p_to EMAIL_ERRORS.TO_NAME%TYPE;
p_from EMAIL_ERRORS.FROM_NAME%TYPE;
p_message EMAIL_ERRORS.MESSAGE_TXT%TYPE;
p_user EMAIL_ERRORS.USER_NAME%TYPE;
p_sys_param_from EMAIL_ERRORS.SYS_PARAM_FROM_TXT%TYPE;
p_attach EMAIL_ERRORS.ATTACH_TXT%TYPE;
P_POST_OP EMAIL_ERRORS.POST_OP_TXT%TYPE;
P_POST_OP_PARAM1 EMAIL_ERRORS.POST_OP_PARAM1_TXT%TYPE;
P_POST_OP_PARAM2 EMAIL_ERRORS.POST_OP_PARAM2_TXT%TYPE;
P_POST_OP_PARAM3 EMAIL_ERRORS.POST_OP_PARAM3_TXT%TYPE;
BEGIN
CAB$MAIL.send (p_to => :P1_TO_NAME
,p_from => :P1_FROM_NAME
,p_message => :P1_MESSAGE_TXT
,p_user => :P1_USER_NAME
,p_sys_param_from => :P1_SYS_PARAM_FROM_TXT
,p_division => :P1_ORG_ID
,p_attach => :P1_ATTACH_TXT
,P_POST_OP => :P1_POST_OP_TXT
,P_POST_OP_PARAM1 => :P1_POST_OP_PARAM1_TXT
,P_POST_OP_PARAM2 => :P1_POST_OP_PARAM2_TXT
,P_POST_OP_PARAM3 => :P1_POST_OP_PARAM3_TXT);
END;
I have states stored in my database with numeric values... as in:
["Alabama", "1"],
["Alaska", "2"],
["Arizona", "3"],
["Arkansas", "4"],
ETC....
When I want to display "Alaska" because the number 2 is being output, how do I do this?
I tried something like this in my controller:
def show
#contact = Contact.find(params[:id])
#state = contact.location_state
end
And have the following in my "show.html.erb":
<%= #state %>
In the case you have to deal with an array of arrays you can get the specific number in the second position of every array accessing to it, with the index [1]:
places = [
["Alabama", "1"],
["Alaska", "2"],
["Arizona", "3"],
["Arkansas", "4"]
]
p places[0][1]
# => "1"
If you have a single one, you don't need to specify the precise array inside the main array of arrays, just with:
place = ["Alabama", "1"]
p place[1]
# => "1"
If you're sending the #state object and want to work with it in your views you can iterate and show the second value corresponding to the number you want to show:
places.each{|place| p place[1]}
# => "1"
# => "2"
# => "3"
# => "4"
Active admin index page i want to hide the column based on some condition , but the below code is not wokrking.
index title: 'Comp-Off', download_links: false do
selectable_column
if proc{ !(current_user.has_role? :Employee) }
column("Name", sortable: :name) {|resource| resource.employee.name}
column("ID", sortable: :employee_id) {|resource| resource.employee.employee_id}
end
column :status
end
How to solve this problem.
It is achieved using the below code.
index title: 'Comp-Off', download_links: false do
selectable_column
column("Name", sortable: :name) {|resource| resource.employee.name} if !(current_user.has_role? :HRMS_Employee)
column("ID", sortable: :employee_id) {|resource| resource.employee.employee_id} if !(current_user.has_role? :HRMS_Employee)
end
column :status
end
I have this code:
array ('id' => 1, 'name' => "Murka", 'date_of_birth' => "2014-10-31", "breed_id" => 1),
array ('id' => 1, 'name' => "Jurka", 'date_of_birth' => "2014-11-31", "breed_id" => 2),
array ('id' => 1, 'name' => "Nyash", 'date_of_birth' => "2014-12-31", "breed_id" => 3),
array ('id' => 1, 'name' => "Meowy", 'date_of_birth' => "2014-01-31", "breed_id" => 4),
array ('id' => 1, 'name' => "Yummi", 'date_of_birth' => "2014-10-31", "breed_id" => 2),
array ('id' => 1, 'name' => "Barss", 'date_of_birth' => "2014-05-31", "breed_id" => 2),
array ('id' => 1, 'name' => "Nonam", 'date_of_birth' => "2014-05-31", "breed_id" => null
I'll want to change all 'id' => 1 (except the 1st) so the number will increment by 1. It's simple to achieve with Emacs:
M-x replace-regexp
\(1,\)
\,(1+ \#),
As described here. After some research the maximum that I've been able to achieve with Vim is (inspired from here):
:let i=1 | g/1,/ s//\=i/ | let i+=1
But this removes all the following commas:
array ('id' => 1 'name' => "Murka", 'date_of_birth' => "2014-10-31", "breed_id" => 1),
array ('id' => 2 'name' => "Jurka", 'date_of_birth' => "2014-11-31", "breed_id" => 2),
array ('id' => 3 'name' => "Nyash", 'date_of_birth' => "2014-12-31", "breed_id" => 3),
array ('id' => 4 'name' => "Meowy", 'date_of_birth' => "2014-01-31", "breed_id" => 4),
array ('id' => 5 'name' => "Yummi", 'date_of_birth' => "2014-10-31", "breed_id" => 2),
array ('id' => 6 'name' => "Barss", 'date_of_birth' => "2014-05-31", "breed_id" => 2),
array ('id' => 7 'name' => "Nonam", 'date_of_birth' => "2014-05-31", "breed_id" => null),
So I have to fix it (I know it's easy).
I am aware of this and macros, I'm just interested to know if there any one-line command solution in Vim.
More general question: is it possible in Vim to inject some logic like conditional statements, manipulating on regex back references? The example for this in Emacs would be:
C-M-% \(^.*\)\(linear-gradient(\)\(to right\|to bottom\)\(.*$\) <RET>
\& C-q C-j
\1-prefix-\2\,(if (equal "to right" \3) "left" "top")\4
This one helped me about a year+ ago to refactor some huge scary HTML code that had a much of inline CSS.
I don't have an answer to your general question, but I do have one for your specific situation. You can make your command work by putting the comma into a positive look-ahead, like this:
:let i=1 | g/1(\,\)\#=/ s//\=i/ | let i+=1
Now it will only replace the 1.
A really easy solution:
:%norm f1s^R=line('.')^M
Obtained like this:
:%norm f1s<C-v><C-r>=line('.')<C-v><CR>
If you are not comfortable with typing complete macros on the command-line you can achieve the same result via recording:
qq
f1s<C-r>=line('.')<CR>
q
[range]#q
Another approach. go to the second line, put the cursor over the first 1, now start a visual block selection Ctrl-v, press j until the line you want increment and press g Ctrl-a