on 07-12-2005 5:58 PM
Hi,
I would like to know how can I put the content of a csv file in a table control? This file is on my computer.
I use a upload file control for upload the csv file in a context variable. How can I use this context variable for populate the table control?
Thank you
What exactly is the problem?
You need to populate a context node "Rows" of cardinality 0:N with the rows of the text file.
If the max. number of columns is bound, let's say at most 10, and all columns have type "string", you can define a context node with 10 attributes A_1, ..., A_10 of type "string" at design time in the IDE.
After having read the CSV file, for each row create a node element e and set attribute e.A_i to the value in column i.
Define an IWDTable with 10 columns, bind the table's data source to the context node "Rows", create 10 IWDTableColumns, use an IWDTextView as table cell editor and bind it's text-property to attribute Rows.A_i.
If the number of columns is less than 10, set the visibility of all unnecessary columns to "Visibility.NONE".
A more sophisticated solution could create the context attributes dynamically, depending on the real number of columns, or could create context attributes of suitable type, if you have this type info.
Armin
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi
Read the file using this
wdComponentAPI.getComponent().getMessageManager().reportSuccess("Inside File Read...");
FileInputStream fin = new FileInputStream("C:/<foldername>/testexcel.xls");
byte b[] = new byte[fin.available()];
fin.read(b,0,b.length);
fin.close();
wdComponentAPI.getComponent().getMessageManager().reportSuccess("File closed after reading...");
element.setDocumentContent(b);
Let me know if that helped you.
regards
ravi
The file-upload UI element stores the file content in a context attribute of DDIC type "binary" which corresponds to byte[] at runtime. There is a constructor in class String which takes a byte array and a charset like UTF-8 which may be used to get a string representation of the file content.
Armin
hi
Say you have value node called "DocumentSourceNode" containing a context attribute called "DocumentContent"
//Then you can read the content
wdContext.currentDocumentSourceNode().getDocumentContent();
This returns a byte array.Well assuming you already have the context filled with data. This will fetch data only then. If its a different scenario let me know.
regards
ravi
Hi
You would like to do something similar to what you do in ABAP. Well you can read the csv file , but for mapping the respective columns you need to know the attributes of the column fields coming from the file meaning you need to know what is the first column field length and so on. Based on this you need to write a logic that would split the columns based on the offset and then accordingly place it in the Table UI.
By the way are the number of columns always fixed or how is it.
If they are fixed then its enough if you set the text of the column fields at runtime.
Hope that was helpful.
regards
ravi
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi
Say your value node is "TableNode". It has 3 columns namely col1, col2 and col3. Now this is bound to the Table ui element right.
Read the data from the csv file and split them based on the offset information you have. ( I guess that logic should be straightforward).
Ensure you store all the columns from the file in a separate context so that it is easy to loop through it .
Now once that is done
IPrivate<ViewName>.ITableNodeElement elt = wdContext.nodeTableNode().createTableNodeElement();
wdContext.nodeTableNode().addElement(elt);
wdContext.currentTableNode().setCol1("col1 from csv");
wdContext.currentTableNode().setCol2("col2 from csv");
wdContext.currentTableNode().setCol3("col3 from csv");
wdContext.nodeTableNode().moveNext();
Hope that helps. This will add the columns to the table.
I guess i have just written it in a hurry.Hope it gives you an idea on what to do. In case you require more info do let me know.
regards
ravi
User | Count |
---|---|
76 | |
10 | |
8 | |
6 | |
6 | |
5 | |
5 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.