Closed XML data validation for allowing any numbers - closedxml

I want to add data validation such that it allows only numbers.CLOSED XML

I think you can do it in memory but you can also use the "Data Validation" in Excel.
But if you use the Excel's data validation you need to be sure that the data you will insert programmatically are only number.
Anyway you can create an excel's templete file with the excel's data validation and than use closedXML for getting the file's template and then insert the data.
Basically for getting the template you can use this code(C#):
var workbook = new XLWorkbook("BasicTable.xlsx");
Info at : https://github.com/ClosedXML/ClosedXML/wiki/Loading-and-Modifying-Files
For the excel's data validation here there are some example :
https://www.got-it.ai/solutions/excel-chat/excel-tutorial/data-validation/data-validation-how-to-allow-numbers-only

Related

how can i write a condition in ssis to verify if the column is a string doesn't contain numbers

i have an excel source to a data base but before i transmit the information in the column product-name i have to verify if the information is a string without numbers in it(example:lion is correct but lion124 is wrong) , using conditional split
and after the verification i have to send a message in an excel file telling the user that the column that he wrote is not correct and if it is correct i will send it to the data base
how could i check for the column and how can i send a excel file ?
I would run it through a script transformation and use c#.
Add a column (boolean) to your data and use this:
Row.NewColForIntTest = Row.YourStringColumn.Any(char.IsDigit);
Then conditionally split off the new column.

Dynamically refer to Json value in Data Factory copy

I have ADF CopyRestToADLS activity which correctly saves json complex object to Data Lake storage. But I additionally need to pass one of the json values (myextravalue) to a stored procedure. I tried referencing it in the stored procedure parameter as #{activity('CopyRESTtoADLS').output.myextravalue but I am getting error
The actions CopyRestToADLS refernced by 'inputs' in the action ExectuteStored procedure1 are not defined in the template
{
"items": [1000 items],
"count": 1000,
"myextravalue": 15983444
}
I would like to try to dynamically reference this value because the CopyRestToADLS source REST dataset dynamically calls different REST endpoints so the structure of JSON object is different each time. But the myextravalue is always present in each JSON call.
How is it possible to refernce myextravalue and use it as a parameter?
Rich750
You could create another lookup active on REST data source to get the json value. Then pass it to the Stored Procedure active.
Yes, it will create a new REST request, and it seams to be an easy way to achieve your purpose. Lookup active to get the content of the source and won't save it.
The another solution may be get the value from the copy active output file, after the copy active completed.
I'm glad you solved it by this way:
"I created a Data Flow to read from the folder where Copy Activity saves dynamically named output json filenames. After importing schema from sample file, I selected the myextravalue as the only mapping in the Sink Mapping section."

Add validation to entire column

In my current project I need to create an excel file with a list validation on an entire column. Googling turned up with the following two results:
http://www.aspose.com/docs/display/cellsnet/Working+with+Validations+in+Columns
This refers to aspose.cells.griddesktop which actually has the worksheet.Columns[n].Validations property. Aspose.Cells doesn't.
http://www.aspose.com/docs/display/cellsjava/Data+Filtering+and+Validation
All the examples use a CellArea which requires a start- and end row.
Anything I missed?
There are two types of excel formats. One is older XLS format and other is newer XLSX format. The number of rows inside the column in XLS format is 65536 and in XLSX format is 1048576. So you can use the above two values to cover your entire column in the CellArea.
You can also use CellArea.CreateCellArea() static method to create cell area object easily
For XLS format, the following CellArea code covers entire column A
CellArea ca = CellArea.CreateCellArea("A1", "A65536");
For XLSX format, the following CellArea code covers entire column A
CellArea ca = CellArea.CreateCellArea("A1", "A1048576");
Note: I am working as Developer Evangelist at Aspose
Here is another way to cover entire column.
// Cover entire column A
CellArea ca = CellArea.CreateCellArea("A", "A");
This will work with both XLS and XLSX format.
Please see the following sample code, execute it at your end and also read its comments. You will get two output Excel files. One in XLS format and other in XLSX format.
Now enter 200 (or any value greater than 100) in these cells and you will get validation error.
A65536
A1048576
C#
// Create workbook
Workbook workbook = new Workbook();
// Accessing the Validations collection of the worksheet
ValidationCollection validations = workbook.Worksheets[0].Validations;
// Cover entire column A
CellArea ca = CellArea.CreateCellArea("A", "A");
// Creating a Validation object
Validation validation = validations[validations.Add(ca)];
// Setting the validation type to whole number
validation.Type = ValidationType.WholeNumber;
// Setting the operator for validation to Between
validation.Operator = OperatorType.Between;
// Setting the minimum value for the validation
validation.Formula1 = "10";
// Setting the maximum value for the validation
validation.Formula2 = "100";
// Save in XLS format
workbook.Save("output.xls", SaveFormat.Excel97To2003);
// Remove the area of validation and add it again
validation.RemoveArea(ca);
validation.AddArea(ca);
// Save in XLSX format
workbook.Save("output.xlsx");
Note: I am working as Developer Advocate at Aspose

In Talend, how do you keep input values provided to tSoap so that you can use them with the Soap response?

I have a Talend Job that currently does the following:
Input CSV --Main--> tMap --Output--> tSoap --Main--> Output CSV
The input CSV has
ID and TYPE as input columns.
The Map creates a Soap XML (String) message using the ID from the CSV and passes that String to the tSoap component.
The tSoap component fires the web request, which sends the response to the next component. That data is then written to CSV.
The problem is that TYPE from the input CSV is not passed through to amalgamate with the SOAP response data. Only the response data seems accessible.
I've had a look at tBufferInput / tBufferOutput and tFlowToIterate but they seem to work in scenarios where the tSoap component does not depend on an input from the main flow.
Does anyone know which components can be used to achieve the amalgamation?
Thank you
If you output the data you need to reuse to a tHashOutput component you should be able to rejoin your data with the response output from tSoap assuming there's some natural join element from the response.
I solved this in the end by:
Placing between the output from the tMap and the input to the tSoap, a new component - tSetGlobalVar
Inside tSetGlobalVar, you can then create a new row, which maps an input column (Value) to a named variable that you specify as the 'Key'.
E.g. Key = "ID", Value = row11.ID
The output from tSetGlobalVar then goes into the tSoap component.
The output from tSoap goes into a new tMap.
Inside this new tMap is the Body column from the previous tSoap component which maps to an output column. To access the stored "ID" variable for the current flow/iteration, I created a new output column, and instead of mapping any columns from the inputs, used (String)globalMap.get("ID"); which would insert the value back into the flow.

Dynamically create a CSV file with FileHelpers

FileHelpers supports a feature called "RunTime Records" which lets you read a CSV file into a DataTable when you don't know the layout until runtime.
Is it possible to use FileHelpers to create a CSV file at runtime in the same manner?
Based on some user input, the CSV file that must be created will have different fields that can only be known at runtime. I can create the needed Type for the FileHelper engine as described in their reading section, but I can't figure out what format my data needs to be in to be written.
var engine = new FileHelpers.FileHelperEngine(GenerateCsvType());
engine.WriteStream(context.Response.Output, dontKnow);
EDIT
Alternatively, can anyone suggest a good CSV library that can create a CSV file without knowing its fields until runtime? For example, create a CSV file from a DataTable.
In fact the library only allows now to read runtime records but for writing purpouses you can use the DataTableToCsv method like this:
CsvEngine.DataTableToCsv(dt, filename);
Let me known if that helps.
I know this is an old question, but I ran into same issue myself and spent some time looking for solution, so I decided to share my findings.
If you are using FileHelpers RunTime Records to create your definition you can populate same definition using reflection.
For example if you create a definition
DelimitedClassBuilder cb = new DelimitedClassBuilder("Customers", ",");
cb.AddField("StringField", "string");
Type t = cb.CreateRecordClass();
FileHelperEngine engine = new FileHelperEngine(t);
Now you can use same type created by FileHelpers to populate your values as follows:
object customClass = Activator.CreateInstance(t);
System.Reflection.FieldInfo field = customClass.GetType().GetField("StringField", System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance);
if (field != null)
{
field.SetValue(customClass, "StringValue");
}
And then write it to file or string:
string line = engine.WriteString(new object[] { customClass });