on 10-27-2007 7:43 AM
Hi Forum
I have a screen which displays a table n from that table i want to dwnld the tabe to .txt file by placing commas between the column....Can anyone help me out on this...
Thanks&Regards
Jaspreet Kaur
Hi,
1.Create a text file.
2. Iterate through the elements of the node bind to the table.
3 Write each element [ concatinate attribute with "," as mentioned by you].
4. Write the element to the file
5. Close the file
Sample Code
StringBuffer strBuf = new Stringbuffer();
for(int x=0; x< wdContext.nodeTest().size(); x++) <b>// Replace nodeTest with yours</b>
{
ITestElement nodeElement = wdContext.nodeTest().getElementAt(x);
strBuf.append(nodeElement.getAttribute("TestAttribute"); //<b>Replace with you</b>rs
strBuf.append(",");
strBuf.append(nodeElement.getAttribute("TestAttribute"); //<b>Replace with you</b>rs
strBuf.append("\n");
}
try
{
FileWriter fileWriter = new FileWriter("data.txt");
fileWriter.write(strBuf.toString());
fileWriter.close();
}catch(Exception e)
{
e.printStackTrace();
}
Regards
Ayyapparaj
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Ayyapparaj
Wut is this string buffer for? Another thing in case of excel we use WDWebResourceType.getWebResourceType() for caching purpose we provide two parameters ie ("xls","application/ms-excel"), is this applicable for a text file?
Thanks & Regards
Jaspreet Kaur
Message was edited by:
Jaspreet Kaur Grewal
hi
I wrote ur code:
StringBuffer strBuf = new StringBuffer();
for(int x=0; x< wdContext.nodeVn_sample().size(); x++) // Replace nodeTest with yours
{
IVn_SampleElement nodeElement = wdContext.nodeVn_sample().getElementAt(x);
strBuf.append(nodeElement.getAttribute("id")); //Replace with yours
strBuf.append(",");
strBuf.append(nodeElement.getAttribute("name")); //Replace with yours
strBuf.append("\n");
}
try
{
FileWriter fileWriter = new FileWriter("data.txt");
fileWriter.write(strBuf.toString());
fileWriter.close();
}catch(Exception e)
{
e.printStackTrace();
}
bu its giving an error in the following line : IVn_sampleElement nodeElement = wdContext.nodeVn_sample().getElementAt(x);
its giving type mismatch:cant convert from IWDNodeElement to IPublicSample.IVN_SampleElement
hi
I wrote ur code:
StringBuffer strBuf = new StringBuffer();
for(int x=0; x< wdContext.nodeVn_sample().size(); x++) // Replace nodeTest with yours
{
IVn_SampleElement nodeElement = wdContext.nodeVn_sample().getElementAt(x);
strBuf.append(nodeElement.getAttribute("id")); //Replace with yours
strBuf.append(",");
strBuf.append(nodeElement.getAttribute("name")); //Replace with yours
strBuf.append("\n");
}
try
{
FileWriter fileWriter = new FileWriter("data.txt");
fileWriter.write(strBuf.toString());
fileWriter.close();
}catch(Exception e)
{
e.printStackTrace();
}
bu its giving an error in the following line : IVn_sampleElement nodeElement = wdContext.nodeVn_sample().getElementAt(x);
its giving type mismatch:cant convert from IWDNodeElement to IPublicSample.IVN_SampleElement
Hi Ayyapparaj
It worked for a single entry, I got the notepad open n got the details written, but i beleive its writing /n as a sumbol..So I will try this into my proj n chk if it works for multiple enteries n get back to u thank u...N shall also award u pts... Thanks a lot
Thanks & Regards
Jaspreet Kaur
hi Ayyapparaj,
I tried for multiple values, its not takin the new line character. Then I tried /0 as its a string termination character, it is gaving a space between the records but not cummin to new line. Is there some way to have the different instances in different rows.
Thanks & Regards
Jaspreet Kaur
Hello,
Try This Code
File f=new File("sample.txt");
FileOutputStream fos=new FileOutputStream(f);
// get values from table ..
// If they are in string format, for each column , say str
fos.write(str.getBytes());
fos.write(",".getBytes());
Regards
LakshmiNarayana
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
80 | |
9 | |
9 | |
7 | |
7 | |
7 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.