cancel
Showing results for 
Search instead for 
Did you mean: 

how to dwnld values from table(ui element) into a text file

Former Member
0 Kudos

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

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

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

Former Member
0 Kudos

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

Former Member
0 Kudos

Hi,

ShiftCtrlO

or right click Source-> Organise Imports.

Use

WDWebResourceType.TXT

Regards

Ayyapparaj

Former Member
0 Kudos

hi Ayyapparaj

Like in case of excel an excel sheet opens directly but in this case its not opening the text file.

Thanks&Regards

Jaspreet Kaur

Former Member
0 Kudos

Hi,

Can you post the code.

Regards

Ayyapparaj

Former Member
0 Kudos

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

Former Member
0 Kudos

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

Former Member
0 Kudos

Hi,

Replace the following line IVn_SampleElement nodeElement = wdContext.nodeVn_sample().getElementAt(x);

with

IVn_SampleElement nodeElement = wdContext.nodeVn_sample().getVn_sampleElementAt(x);

Regards

Ayyapparaj

Former Member
0 Kudos

now my code is error free but i am not able to see the txt file.

Former Member
0 Kudos

this is the change i had done:

strBuf.append(nodeElement.getId()); //Replace with yours

strBuf.append(",");

strBuf.append(nodeElement.getName()); //Replace with yours

strBuf.append("\n");

Former Member
0 Kudos

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

Former Member
0 Kudos

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

Former Member
0 Kudos

Hi

Try out giving

strBuf.append("\r\n");

Regards

Akshaya

Answers (1)

Answers (1)

Former Member
0 Kudos

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