Validate microsoft Excel data cell in Java - java

How to validate excel's column in Java spring? Validation such as column should be string or not null. After read Excel file, do validation then all data will be store in database's table.

The short answer to that is: you, probably, have to use the JXL library (or something similar). It allows you to access concrete cells in Excel sheets and get their values (amongst other things).

Related

Parameterization using CSV to JSON (Different data types)

I am trying to parameterize a Webservice from a CSV file to JSON.
In my CSV file (screen shot), the values I need are in the 6th row as shown. I get this error:
Failed not able to load
passing blank values (Debug)...
When I try to pass the values from the 8th row, the operation completes successfully.
But in my case, how can I provide or convert the values to String or Int for parsing them as JSON using a preprocessor?
I need to convert the values like this: 6th-8th row from the CSV file to JSON and then pass to Jmeter-JSON request. We use MONGODB.
Is this possible to covert in jmeter?
You cannot keep JSON in CSV because CSV is comma-separated values and commas are widely in JSON.
If you cannot change the source data format I can only suggest switching to Excel and reading the data from the cells using Apache POI API
More information:
Busy Developers' Guide to HSSF and XSSF Features
How to Implement Data Driven Testing in your JMeter Test

Compare input file Excel (one or more columns will be in excel) and compare same columns in database and return unmatched data and export it to excel

I'm trying to create a small application to get data from database and export it to excel.
I want to compare input file Excel (one or more columns will be in excel) and compare same columns in database and return unmatched data and export it to excel.
For example if excel file has Columns: Account,Account Id
Database may have columns : Account,Account Id, Name,Address
process should compare Account and Account ID then return Account ID which are not in database.
Also file may contain huge data.
Please advise how to compare and extract data to excel using Java only.
You can achieve this by importing Apache POI library and have it in your build path
I find this source very useful Comparing two excel inputs

Using ORMLite to create table from Excel data

I have an Excel file with headers and rows. I've already got the Excel side "handled", thanks to Apache's excellent POI libraries. I can access the rows, headers, etc.
What I want to do now is create a database table based on the header information (column names) and using some parsing logic to establish the datatypes of the rows (already done).
I've used ORMLite very successfully in the past with known Java classes.
Is there a more elegant method than "hacking" a Java object together dynamically that matches the Excel data columns?
I'd like to get as close to this as possible:
Table t = conn.createTable("Table Name") ;
t.addColumn ("Column Name", String.class, 30) ; // Col name, data type, length
t.addColumn ("Another Column", Number.class, 5) ;
etc.
I know ORMLite can createTables based on an existing class (which is awesome), I'd like to have an API to create table data.
Looking at the ORMLite docs, TableUtils.createTable(...) still needs a Java class, as does DatabaseTableConfig.
If not ORMLite, any other suggestions? Thanks in advance.
PS: The whole reason for this to not get tangled up in SQL dialect differences. I want to build this into a robust tool to open source. Besides, it ought to be in the JDBC API but its' not. It seems very poor design to have to write lots of:
String sql="CREATE TABLE xxx ..."; // each slightly different for each DB

How to read and store data from excel using java for selenium?

I would like to take an opportunity from you, am facing an issue to read and storing the data from excel.
Requirement: in my excel sheet having 10 rows and 5 columns, out of 10 rows I just want to execute only 5 rows(1,2,4,7,9)based on my flag status (YES/NO).
i want to read all required data from excel only one time and then need to get release excel.
what am exactly expecting, need to map like 1(row) with column and value
ex: 4 the row(test case) mapping with all columns and their values against to 4th row.
like 4,(col,value)
when i go for read ,i want fetch values from column names based on the row number(ex: 4 th test case)
i tried this way but didn't work for me,
HashMap<Integer,String[]> mymap=new HashMap<Integer,String[]>
mymap.put(rownumber(testcasenumber),new string[]{getcelldata(col),getcelldata(colval)});
in this case storing only test case number(r=row num) but other info col,values are not storing.
please assist me to get exact and perfect way for this.
Perhaps using a Java API for excel such as JExcel at http://jexcelapi.sourceforge.net/ or Apache POI at http://poi.apache.org/ can do what you want.

Parse Excel Spreadsheet into model in java

I have an excel spreadsheet that contains service delivery information for a single client at a time. For example, Max Inc will be provided with health assessments at 3 of their corporate offices. An office may have deliveries of health assessments (service type) on multiple days and performed by different doctors.
I've created what I believe to be JavaBeans to ultimately represent all this information and the relationship between entities such as client, delivery, service, and individual sessions in a delivery.
My problem now is, what is the best way to read in and parse the data from the excel spreadsheet?
I was thinking I could create a static util class (like a factory class) that reads the excel spreadsheet (using Apache POI HSSF) in one method and then uses a variety of other methods to parse the data from the spreadsheet and then ultimately return a client object which contains all the other objects and so on.
During some point during this process I also need some data from a SQL Server DB which I thought I will just pull in using JDBC as needed.
Am I heading in the right direction with this approach? Or would recommend doing this another way?
Try simplifying this a little. Save the spreadsheet as a CSV file which is really easy to import into Java and subsequently into a database.
You could use a BufferedReader to read in the strings and split them at each delimiter ",". With each split String you will get an Array which you can add to your database.
Definitely try and avoid interfacing with Excel.
Simply reading cells from an Excel sheet is easy with POI. See: http://poi.apache.org/spreadsheet/quick-guide.html#CellContents
This will avoid any manual steps like converting to another format.
All you really need is a factory method to read in the spreadsheet and return back a list of objects. Then you can do your thing.

Categories