Set number format to General - excel

I want to set a specific value in a table to default format "General".
To implement this I follow the spec:
Blank and null values in Excel add-ins
When you specify a blank value for a property (i.e., two quotation
marks with no space in-between ''), it will be interpreted as an
instruction to clear or reset the property. For example:
...
If you specify a blank value for the
numberFormat property, the number format is reset to General.
...
My code is:
const formats = [["0", "0"], ["", "0.00"], ["0.00", "0.00"]];
const range = sheet.getRange("D3:E5");
range.numberFormat = formats;
The usage of empty quote lead to an error message from the excel.js API :
message: "The argument is invalid or missing or has an incorrect format."

Related

#Error when exporting to .csv from ssrs when trying to replace a comma with another field

I am trying to replace a comma with another field so you can import the data using a csv. I can do that successfuly by adding .ToString().Replace(","," And ") to the end of the field
EX. Fields!Fieldname.Value.ToString().Replace(","," And ")). This will replace the comma with the word And.
The issue I have encounterd is when the field is blank. It then exports a #Error in the cell. I have tried hiding the cell if it is blank but that works for everything but when it exports to a .csv.
If I cannot get the field to be just blank I would like to have it display 99.
Please help.
I have tried this as well...
=Iif(isNothing(Fields!FieldName.Value),"99",(Fields!FieldName.Value.ToString().Replace(","," And ")))
It still displayed an error
The problem is that you are trying to convert NULL (Nothing) to a string. Both sides of IIF are evaluated so even though you will never see the result, false part is failing when FieldName is null.
TO get round this, we first check if the field is null, then replace that with and emptry string "" and then do the ToString() bit.
try the following...
=IIF(
isNothing(Fields!TestField.Value),
"",
(IIF(IsNothing(Fields!TestField.Value),
"",
Fields!TestField.Value
).ToString().Replace(","," And "))
)

The string '0000-00-00' is not a valid AllXsd value

I am calling a SAP BAPI in the logic app. I have several date fields as input parameters which does not need a value to be passed. So all the date fields are being sent as blank (in postman).
When the logic app calls the SAP BAPI all the date fields are defaulted to 0000-00-00. and I get the error
The string '0000-00-00' is not a valid AllXsd value.
I also tried to change the type in schema to date , but that does not help either.
enter image description here
The error is occuring as the date had been defaulted 0000-00-00.
Receive the date as a string.
"DLV_DATE":
{
"type": "string"
}
Handle for the blank values (0000-00-00).
Rather than being defaulted 0000-00-00 - you can perform a check and if it is null, you can set it to current date and pass it subsequently in the next step

Hapi/Joi Validation For Number Fails

I am trying to validate number value which will include integer as well as float values. Following is my implementation for the same.
Joi Schema.
const numcheckschema = Joi.object().keys({
v1:Joi.number().empty("").allow(null).default(99999),
v2:Joi.number().empty("").allow(null).default(99999),
v3:Joi.number().empty("").allow(null).default(99999)
})
Object
objnum={
v1:"15",
v2:"13.",
v3:"15"
}
objValidated = Joi.validate(objnum, numcheckschema);
console.log(objValidated);
When i execute the above mentioned code I get an error
ValidationError: child "v2" fails because ["v2" must be a number]
as per the documentation when we tries to pass any numeric value as a string it converts the values to number but here in this case my value is 13. which is not able to convert into number and throwing an error.
Is there any way by which we can convert this value to 13.0
You can use a regex in order to match numbers with a dot, for instance:
Joi.string().regex(/\d{1,2}[\,\.]{1}/)
And then combine both validations using Joi.alternatives:
Joi.alternatives().try([
Joi.number().empty("").allow(null),
Joi.string().regex(/\d{1,2}[\,\.]{1}/)
])
However, I think you may need to convert the payload to number using Number(string value). You need to check the payload type, if it isn't a Number, you need to convert it.
If you want to know more about the regex used in the example, you can test it in here: https://regexr.com/

New line symbol when exporting to excel

I need to fill a cell with a data, separated by 'new line' symbol.
I've tried:
data: l_con_sepa TYPE c VALUE cl_abap_char_utilities=>newline.
...
CONCATENATE <gf_aufk>-tplnr " 6000000159 Korchagin AS 02.02.2017
<gf_aufk>-pltxt
l_con_sepa
<gf_aufk>-aufnr
INTO lv_str
SEPARATED BY space.
Tried to use CL_ABAP_CHAR_UTILITIES=>CR_LF. Tried to use "&" and "#" symbols. Tried to wrap lv_str with quotes. Nothing.
I either got symbols as is, or just a blank space insted of 'alt+enter' equivalent.
A simple experiment with Excel, namely creating a cell with Alt+Enter characters and saving it as a CSV file, shows that such a new line symbol is LF and not CR_LF. Moreover it is put there in double quotes.
So just use double quotes and CL_ABAP_CHAR_UTILITIES=>NEWLINE.
It must work with CSV. You did not specify what API you use to export your data to XLS format, so I cannot test it. If you do not mind putting those details in the question, please do so.
Assuming you use FM SAP_CONVERT_TO_XLS_FORMAT, there is even no need for double quotes.
REPORT YYY.
TYPES: BEGIN OF gty_my_type,
col1 TYPE char255,
col2 TYPE char255,
END OF gty_my_type,
gtty_my_type TYPE STANDARD TABLE OF gty_my_type WITH EMPTY KEY.
START-OF-SELECTION.
DATA(gt_string_table) = VALUE gtty_my_type(
(
col1 = 'aaa'
&& cl_abap_char_utilities=>newline
&& 'bbb'
&& cl_abap_char_utilities=>newline
&& 'ccc'
col2 = 'ddd'
)
).
CALL FUNCTION 'SAP_CONVERT_TO_XLS_FORMAT'
EXPORTING
i_filename = 'D:\temp\abap.xlsx'
TABLES
i_tab_sap_data = gt_string_table
EXCEPTIONS
conversion_failed = 1
OTHERS = 2.
ASSERT sy-subrc = 0.
The result looks like follows
I thought that it might be caused by CONCATENATE .. INTO .. SEPARATED BY space but it is not. Please execute the following program in order to check it out.
REPORT YYY.
TYPES: BEGIN OF gty_my_type,
col1 TYPE char255,
col2 TYPE char255,
END OF gty_my_type,
gtty_my_type TYPE STANDARD TABLE OF gty_my_type WITH EMPTY KEY.
DATA: gs_string TYPE gty_my_type.
DATA: gt_string_table TYPE gtty_my_type.
START-OF-SELECTION.
CONCATENATE 'aaa' cl_abap_char_utilities=>newline 'bbb' cl_abap_char_utilities=>newline 'ccc'
INTO gs_string-col1 SEPARATED BY space.
gs_string-col2 = 'ddd'.
APPEND gs_string TO gt_string_table.
CALL FUNCTION 'SAP_CONVERT_TO_XLS_FORMAT'
EXPORTING
i_filename = 'D:\temp\abap.xlsx'
TABLES
i_tab_sap_data = gt_string_table
EXCEPTIONS
conversion_failed = 1
OTHERS = 2.
ASSERT sy-subrc = 0.
So the problem must be somewhere else. You are not showing us your whole code. Maybe you use some kind of a third party package to process your Excel files?
I don't remember if it's needed to add an "end of line" symbol.
Just append each line into a table and download the full table using FM SAP_CONVERT_TO_XLS_FORMAT.

Deleting contents of a string - TextBox behaves slightly differently from DataGridView text cell

If you set up a simple test form with a TextBox bound to a string property of a class and delete the content the value passed back to the property setter is "".
If you do the same thing with a cell in a DataGridView the value passed back to the property setter is Nothing.
Why the difference and is there anything we can apply to the DataGridView to make it behave the same as a TextBox?
if am correct the DataGridViewTextBoxCell by default is Null and the TextBox by Default is String.Empty
you might check the Null vs Empty
Nothing is VB's version of C#'s null or a database's NULL. It means that there is no value, as opposed to "" which means that there is a value, of an empty string.
I'm not entirely sure, but I suspect the difference is because a textbox's Text property is always a string, but a cell's Value property can be any object. You can use the null-coalescing operator to return an empty string when the value is Nothing.
Set(ByVal value As String)
_Surname = If(value, "")
End Set
Alternatively, you can validate the cell post-edit and set it to ""explicitly. see here for an example - instead of messaging the user, you'd just change the value.
DataGridView converts "" into Null during cell parsing.
If you handle CellParsing event and just set ParsingApplied, then no further parsing will be performed and the resulting value will remain "".

Resources