I was given a task of generating a CSV file. I am facing some issues at this moment.
The problem statement goes something like this:
I am getting some data (preferably column wise from database), and this fetching of data happens at the runtime.
For example: I am passing the required column COLUMN_A_VAL, COLUMN_D_VAL, COLUMN_C_VAL, etc… to database to fetch the records. This fetching of the record is not in order, sometimes the order can be A,B and C. and sometimes, it is, C, B, A.
Once after getting the data from database tables, I am converting this to a string. And, I have the data in the string as follows:
Column A
data 1
data 2
data 3
data 4
.
.
.data n
Now, I will retrieve one more set of columns from DB table, say, Column B.
Column B
data 1
data 2
data 3
.
.
.data n
Finally, I need to generate the CSV file in a format like this:
Column A, Column B,
data 1, data 1
data 2, data 2
data 3, data 3,
…, …,
…, …,
data n, data n
My question here is: How can I append the data in a CSV file Column wise.
P.S.: I have tried “convertToString” service from flat-file package, But, this works for a predetermined columns.
But, what I have is, everytime I had to determine which column has the data, and particularly, fetch the data from that DB Table, and append it to the file.
Can someone throw some insights on to how to generate/append the string data into a CSV file column wise with comma as delimiter.
I have tried many options, but, couldn’t succeed still!!
Thanks for the heads up :), It worked slightly nearer the way you told with little tweaking up in between.
Since, the stringTable is multi-dimensional array, I had to get both the indicies for row and column as well.
Finally, it worked and I could able to generate the CSV file in the required format that I was asked to get it. Phew!!
However, I have found out this thread,
Which explains solution to my problem to the exactness.
I would like to know if there is a way to do the other way around? I have the columns on a CSV and I need to parse into a document type. I know I can use Flat File Schema/Dictionary, but I don’t know how to do it.
Have you had a chance to look at the Flat File Schema Developer’s Guide? I would start there. If after reading the guide, you have more questions, please let us know.