Explanation of algorithm that get the excel column title - excel

According to this topic:
How to convert a column number (e.g. 127) into an excel column (e.g. AA)
I don't understand what is in algorithm:
here
Could someone explain me, what is happening in a while loop?

It is, in effect, "converting" the column number to base 26, where the "digits" are the letters A..Z.
For example, for column 720:
modulo = (720-1)%26 = 17
columnName = 'R'
dividend = (720-17)/26 = 27
modulo = (27-1)%26 = 0
columnName = A+columnName = AR
dividend = (27-0)/26 = 1
modulo = (1-1)%26 = 0
columnName = A + columnName = AAR
dividend = (1-0)/26 = 0
Resulting in AAR.

Related

How to Display Header with length Greater then 40 CHAR In SALV?

I would like to know is there any way to set Header with 60 char in SALV? Since there is a CHAR limit of 40 when I try using SET_LONG_TEXT method. I am using this SALV to both display and download it as an excel too.
My Prod Code looks like this below.
TRY.
" Call SALV Factory Method
cl_salv_table=>factory(
EXPORTING
list_display = abap_false
IMPORTING
r_salv_table = DATA(lo_salv)
CHANGING
t_table = <fs_global_factor_data> ).
DATA(lo_columns) = lo_salv->get_columns( ).
lo_columns->set_optimize( ).
DATA(lo_col_ref) = lo_columns->get( ).
" Get the Field Description in the table
lr_strucdesc ?= cl_abap_typedescr=>describe_by_data( ls_struct ).
/stl/cl_gf_validations=>at_gf_table_struct = lr_strucdesc->get_ddic_field_list( ).
Here, I am replacing the long text with my own texts with a length of 60 Char from the AT_FIELD_HEADER table.
" Remove Short and Medium texts and Replace long texts from AT_FIELD_HEADER Table
LOOP AT lo_col_ref ASSIGNING FIELD-SYMBOL(<fs_col_ref>).
<fs_col_ref>-r_column->set_short_text( space ).
<fs_col_ref>-r_column->set_medium_text( space ).
<fs_col_ref>-r_column->set_fixed_header_text( lc_char_l ) .
<fs_col_ref>-r_column->set_long_text( SWITCH #( <fs_col_ref>-columnname+0(5) WHEN /stl/cl_gf_validations=>ac_desc_field_prefix THEN /stl/cl_gf_validations=>ac_fd_description
ELSE CONV #( LET line = VALUE /stl/cl_gf_validations=>ty_field_header( /stl/cl_gf_validations=>at_field_header[ fieldname = <fs_col_ref>-columnname ] OPTIONAL )
IN COND #( WHEN line-title IS NOT INITIAL THEN line-title ELSE line-description )
) ) ).
ENDLOOP.
DATA(lv_xml_type) = if_salv_bs_xml=>c_type_xlsx.
DATA(lv_data_in_xstring) = lo_salv->to_xml( xml_type = lv_xml_type ).
CATCH cx_root.
MESSAGE e033(/stl/bw_gf_msg).
ENDTRY.
" Convert XSTRING TO BIN
CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
EXPORTING
buffer = lv_data_in_xstring
IMPORTING
output_length = lv_file_size
TABLES
binary_tab = lt_data_in_bin.
Here, GUI_DOWNLOAD is used to download it as an excel file.
" Download the Excel
cl_gui_frontend_services=>gui_download(
EXPORTING
bin_filesize = lv_file_size
filename = lv_fullpath
filetype = lc_filetype_bin
CHANGING
data_tab = lt_data_in_bin
EXCEPTIONS
file_write_error = 1
no_batch = 2
gui_refuse_filetransfer = 3
invalid_type = 4
no_authority = 5
unknown_error = 6
header_not_allowed = 7
separator_not_allowed = 8
filesize_not_allowed = 9
header_too_long = 10
dp_error_create = 11
dp_error_send = 12
dp_error_write = 13
unknown_dp_error = 14
access_denied = 15
dp_out_of_memory = 16
disk_full = 17
dp_timeout = 18
file_not_found = 19
dataprovider_exception = 20
control_flush_error = 21
not_supported_by_gui = 22
error_no_gui = 23
OTHERS = 24
).
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
Also, I am using the same piece of code to display the SALV where header gets truncated to 40 char.

Grading system in excel sheet based on marks

I am trying to paste grades in excel sheet based on marks
i do this but this shows only F in excel sheet .. i want if anybody has marks >=80 then want to show A grade .. and if anybody hay >=70 then B
and if anybody have less than 70 then want to show F
UPDATED CODE
clc,clear all
filename = 'PROJECT..xlsx';
table = readtable(filename);
data = xlsread(filename);
[r,c] = size(data);
total_courses = c;
table.SumofMarks = zeros(r,1);
table.Percentage = zeros(r,1);
table.StudentGrade = repmat({''},r,1);
% Sum of marks in different courses and their percentage.
format bank
Sum_of_Marks = sum(data,2);
Student_Percentage = Sum_of_Marks./total_courses;
T = horzcat(Sum_of_Marks,Student_Percentage);
N = length(Student_Percentage);
table.SumofMarks = Sum_of_Marks;
table.Percentage = Student_Percentage;
for i = 1:63
sheet1=readtable(filename);
mark=sheet1{i,{'CALCULUS','DISCRETE','ECONOMICS','ISLAMIAT','STATISTICS'}};
if mark(mark<40)
grade='F';
sheet1(i,'StudentGrade')=cellstr(grade);
else
continue
end
end
writetable(table,filename)
xlswrite(filename,T,1, 'H2')
xlswrite(filename,grade,1,'J2')
these are the errors which I get
Error using getRowIndices (line 75)
Row index exceeds table dimensions.
Error in table/subsrefBraces (line 17)
[rowIndices,numRowIndices] =
getRowIndices(t, s(1).subs{1});
Error in table/subsref (line 60)
[varargout{1:nargout}] =
subsrefBraces(t,s);
Error in lab4 (line 38)
mark=sheet1{i,{'CALCULUS','DISCRETE','ECONOMICS','ISLAMIAT','STATISTICS'}};
i tried this but this code doesnt work
how i do this
i paste link where my file is located.. and I want if any student get less than 40 marks in any subject then want to show F grade.. this code shows if total marks is less than 40 .. where as I want to show if marks is less than 40 in any subject
this is the excel file
https://drive.google.com/file/d/1VQ8XxAQPu6reY0SCNV9Rxt65w1koduGA/view?usp=sharing
I don't have Excel installed, so I can't check the part about reading and writing to Excel, but you should replace
if R>=80
table.StudentGrade{i} = 'A';
elseif R>=70
table.StudentGrade{i} = 'B';
elseif R <70
table.StudentGrade{i}= 'F';
end
with
if R(i)>=80
table.StudentGrade{i} = 'A';
elseif R(i)>=70
table.StudentGrade{i} = 'B';
elseif R(i) <70
table.StudentGrade{i}= 'F';
end

replace fraction with decimal in Excel using vbscript

As part of a larger script, I am trying to replace fraction values with decimal values in excel using vbscript. I can always count on the values to have a specific column and a specific format.
Excel example expected input column B:
51-7/16
1-1/2
2
15-7/8
Excel example desired output column B:
51.4375
1.5
2
15.875
I know it will always be to a 1/16th. So my idea was to go through the list looking for each possible fraction, find a cell that contains that fraction, and replace it with the corresponding decimal.
Questions: How do I tell the script to find a cell that contains a value and how do I replace that fraction with the decimal?
closest example Search and Replace a number of characters in Excel using VBscript
Attempt:
Dim FMember (14)
FMember(0) = "-1/16"
FMember(1) = "-1/8"
FMember(2) = "-3/16"
FMember(3) = "-1/4"
FMember(4) = "-5/16"
FMember(5) = "-3/8"
FMember(6) = "-7/16"
FMember(7) = "-1/2"
FMember(8) = "-9/16"
FMember(9) = "-5/8"
FMember(10) = "-11/16"
FMember(11) = "-3/4"
FMember(12) = "-13/16"
FMember(13) = "-7/8"
FMember(14) = "-15/16"
Dim DMember(14)
DMember(0) = ".0625"
DMember(1) = ".125"
DMember(2) = ".1875"
DMember(3) = ".25"
DMember(4) = ".3125"
DMember(5) = ".375"
DMember(6) = ".4375"
DMember(7) = ".5"
DMember(8) = ".5625"
DMember(9) = ".625"
DMember(10) = ".6875"
DMember(11) = ".75"
DMember(12) = ".8125"
DMember(13) = ".875"
DMember(14) = ".9375"
Dim endRow2
endRow2 = objSheet2.UsedRange.Rows.Count
For lngPosition = LBound(FMember) To UBound(FMember)
For r = 1 To endRow2
If objSheet2.Cells(r, objSheet2.Columns("B").Column).Value = FMember(lngPosition) Then
objSheet2.replace
End If
Next
Next
Use split()
Function fract(str As String) As Double
Dim strArr() As String
If InStr(str, "-") Then
strArr = Split(str, "-")
fract = strArr(0) + Application.Evaluate(strArr(1))
Else
fract = Application.Evaluate(str)
End If
End Function
Then you can use it as a worksheet function:
=fract(A1)

How do I only loop through certain parts of a cell array?

I am trying to figure out a way to make a for loop in which I can compare two cells that will give me two different means. One for class char and the other for class double.
This is what I have so far.
V = {2; 'tree'; 3; 'hope'};
W = {2; 'tree'; 3; 'hope'};
for i = 1:length(V);
if isequal(class(V{i}), 'double')
num = V{i}
elseif isequal(class(V{i}), 'char')
str = V{i}
end
end
for i = 1:length(W);
if isequal(class(W{i}), 'double')
acc_n(i) = isequal(V{i}, W{i})
elseif isequal(class(W{i}), 'char')
acc_s(i) = strcmp(V{i}, W{i})
end
end
mean_d = mean(acc_n)
mean_s = mean(acc_s)
The output I get is:
acc_n =
1 0 1
acc_s =
0 1 0 1
mean_d =
0.6667
mean_s =
0.5000
The output I want is:
1 1 for string, mean = 1. 1 1 for double, mean = 1
How can I do a loop where it only takes the numbers of the cell and the words of the cell separately?
Is there any possible way to only loop through the words or the numbers?
You can first extract strings and doubles and treat them separately, that will avoid loops.
V = {2; 'tree'; 3; 'hope'};
W = {2; 'tree'; 3; 'hope'};
VChar=V(cellfun(#ischar,V));
WChar=W(cellfun(#ischar,W));
acc_s=VChar==WChar;
VNum=cell2mat(V(cellfun(#isnumeric,V)));
WNum=cell2mat(W(cellfun(#isnumeric,W)));
acc_n=VNum==WNum;
Loop version: I haven't tested this but it should work.
%Assumes V and W have equal number of elements.
acc_n=[];
acc_s=[];
for i=1:numel(V)
if isequal(class(V{i}), 'double') && isequal(V{i},W{i})
acc_n=[acc_n true];
elseif isequal(class(V{i}), 'char') && strcmp(V{i},W{i})
acc_s=[acc_s true];
end
end

how can remove decimal place after value in C#?

Let I have decimal value of 14.8447 and I need this value 8447 in string.
Can any one find any way for me using window Forms C#.
You could use something like:
decimal d = 14.8447m;
string s = d.ToString(CultureInfo.InvariantCulture);
string t = s.Substring( s.IndexOf('.')+1);
(Although I think my code is a bit of a hack)
To make it a little bit more error-proof, you could write:
decimal d = 14.8447m;
string s = d.ToString(CultureInfo.InvariantCulture);
int index = s.IndexOf('.');
string t = index >= 0 && index + 1 < s.Length
? s.Substring(index + 1)
: string.Empty;
This works well with e.g. the following numbers:
decimal d = 14m; // Returning empty string.
decimal d = .3m; // Returning "3".
Here is a short online version at Ideone.com.
string.Format("{0:0.0000}", 14.8447m).Split(',', '.').Last()
Could be so:
decimal Numero = 8.24M;
string r = (Numero - Math.Floor(Numero)).ToString().Replace("0.", "");
Easy I guess;

Resources