How to extract numeric value instead of text from GuiTableControl? - excel

I use Excel VBA to automate tasks in SAP.
Many times when dealing with GuiTableControl​ the numbers and dates are formatted as text, not values. That causes problems when users have different settings (commas and points as decimal separator, for example).
Is there a function like getcellvalue in GuiGridView?
A workaround would be to access the User Profile in System/User Profile/Own Data/Defaults to get the default format for the current user, and create a function to convert the text to a value depending on the default format.

Try declaring a variable and using the "text" property of the field from the script. For example:
myVariable = session.findById("wnd[0]/usr/tabs_blah_blah").Text
Then use the variable in Excel to populate the formulae to convert in the correct way.

Related

Save number format by default in Excel

I would like to save number format with comma delimiter as default in Excel.
So number 123456.78 will always look like 123,456.78
How can I do this ?
Excel general number formatting is based on your locale. This contains a "Digit grouping symbol", filling this is will change your format accordingly.
Be aware this is not only done for Excel, but for every application on your computer, based on this format.
Home/Styles: Right click on Normal and select Modify
Change the Number style
from General either to Number + use thousands separator
or, if you want to use Scientific notation when over a certain amount, perhaps
[<100000000]#,##0.00;General
or whatever you want.

Retrieve Format of a NotesViewColumn

Is there a way to find out which format applies to a NotesViewColumn? I can see that there are a number of format attributes e.g. DateFmt, TimeDateFmt, NumberFormat etc, but what I can't see is a way to identify which one of them applies.
Combine your current column's value type with NotesViewColumn's format attributes.
If your current column value is of type number then use
NotesViewColumn's NumberFormat, NumberAttrib, NumberDigits format.
If your current column value is of type NotesDateTime then use
NotesViewColumn's DateFmt, TimeDateFmt, TimeFmt, TimeZoneFmt format.
Assuming you are able to read NSF design, you could rely on DXL export to get the information needed. Try the DXL utility on Tools - DXL Utilities - Viewer:
As you may find, the piece of information you need is nested inside every <column> node.
For number columns there is a <numberformat> node.
For time columns there is a <datetimeformat> node above <numberformat>.
For text columns there is nothing.
In case you need to programaticaly analyse a number of views, there is the NotesDXLExporter on hand.

Is there a character in Excel to mask a STRING using TEXT function?

Is there a character to mask STRING values within the Excel TEXT function?
Attempting to use a mask of "0000-000000-00000-0000" seems to convert a string to a number. I simply want to add hyphens in between a specific number of characters.
I have also tried "####-######-#####-####" and "####-######-#####-####" but to no avail.
Background:
In a previous question, it was determined that a particular custom number mask could not be applied to a string because of the 15 significant digit limitation in Excel.
The goal was to convert a TEXT value of 5145350002005000080 to 5145-350002-00500-0080 using the following formula:
=text(A1,"0000-000000-00000-0000")
The output produced was:
5145-350002-00500-0000
You will need to use Excel string functions.
This works, though it is not the usual way of getting the job done:
=REPLACE(REPLACE(REPLACE(A1,16,0,"-"),11,0,"-"),5,0,"-")
The more typical method:
=LEFT(A1,4)&"-"&MID(A1,5,6)&"-"&MID(A1,10,5)&"-"&RIGHT(A1,4)
Unfortunately it's impossible to apply markup to any string value using TEXT - as per TEXT function description, it may be done only for numbers:
The TEXT function converts a numeric value to text and lets you
specify the display formatting by using special format strings.
Syntax
TEXT(value, format_text)
The TEXT function syntax has the following arguments:
value Required. A numeric value, a formula that evaluates to a numeric value, or a reference to a cell containing a numeric value.
So it looks like the only way for you to achieve what you want - is to apply recommended string conversions.
Select the cells->Press Ctrl+1->from Number Tab of Format Cells Dialog select "custom" and paste in Type edit box Below.
"Boxes";"Boxes";"Boxes";"Boxes"
Source: Here

FIxing MS Excel date time format

A reporting service generates a csv file and certain columns (oddly enough) have mixed date/time format , some rows contain datetime expressed as m/d/y, others as d.m.y
When applying =TYPE() it will either return 1 or 2 (Excel will recognize either a text or a number (the Excel timestamp))
How can I convert any kind of wrong date-time format into a "normal" format that can be used and ensure some consistency of data?
I am thinking of 2 solutions at this moment :
i should somehow process the odd data with existing excel functions
i should ask the report to be generated correctly from the very beginning and avoid this hassle in the first place
Thanks
Certainly your second option is the way to go in the medium-to-long term. But if you need a solution now, and if you have access to a text editor that supports Perl-compatible regular expressions (like Notepad++, UltraEdit, EditPad Pro etc.), you can use the following regex:
(^|,)([0-9]+)/([0-9]+)/([0-9]+)(?=,|$)
to search for all dates in the format m/d/y, surrounded by commas (or at the start/end of the line).
Replace that with
\1\3.\2.\4
and you'll get the dates in the format d.m.y.
If you can't get the data changed then you may have to resort to another column that translates the dates: (assumes date you want to change is in A1)
=IF(ISERR(DATEVALUE(A1)),DATE(VALUE(RIGHT(A1,LEN(A1)-FIND(".",A1,4))),VALUE(MID(A1,FIND(".",A1)+1,2)),VALUE(LEFT(A1,FIND(".",A1)-1))),DATEVALUE(A1))
it tests to see if it can read the text as a date, if it fails, then it will chop up the string, and convert it to a date, else it will attempt to read the date directly. Either way, it should convert it to a date you can use

Prevent comma-separated list of numbers being interpreted as single large value

33266500,332665100,332665200,332665300 was the original value, cell should look like this: 33266500,332665100,332665200,332665300 but what I see as the cell value in excel is 3.32665E+34
So the question is I want to convert it into the original string. I have found format function on google and I used it like these
format(3.32665E+34,"standard")
giving it as 332,6650,033,266,510,000,000,000
How to parse it or get back the orginal string? I belive format is the function in vba.
Excel has a 15 digit precision limit. If the numbers are already shown like this when you access the file, there is no way to get the number back - you have already lost some digits. VBA code and formulas will not help you.
If this is not the case, you can add a single quote ' mark before the number to store it as text. This will ensure Excel does not try to treat it as a number and thus lose precision.
If you want the value kept exactly, store the data as a string, not as a number. The data type you are using simply doesn't have the ability to do what you are asking it to do.
If you're starting with an Excel file that has already been created then you've already lost the information: Excel has tried to understand what it was given and its best guess has turned out to be wrong. All you can do (if you can't get the source data) is go back to the creator of the Excel file and tell them what's wrong.
If you're starting with, say, a text file that you're importing, then the news is much better:
If you're importing manually using the Text Import Wizard, then at "Step 3 of 3" you need to set "Column Data Format" for the problem field to "Text".
If you're using a macro, you'll need to specify a value for the TextFileColumnDataTypes property that does the same thing. The easiest way to get it right is to use the Macro Recorder.
If you want the four values in the string to be separate cells, then again, look at the Text Import Wizard settings: in Step 1 of 3 you need to set "Delimited" data type (usually the default) and in Step 2 make sure that "Comma" is checked.
The value needs to be entered into the cell as a string. You need to make whatever it is that inserts the value preceed the value with a '.

Resources