cancel
Showing results for 
Search instead for 
Did you mean: 

Excel Download

sid-desh
Advisor
Advisor
0 Kudos

Hi,

I have a table with two columns on my view and a file download UI element separately. Using the File Download UI i want to download the table data to Excel. I have written the following code. The problem is that all the data in getting downloaded in a single cell of Excel i.e. in cell A1. Please advise as what i am doing wrong.

<i>IWDAttributeInfo attrInfo = wdContext.nodeDownload().getNodeInfo().getAttribute("data");

ISimpleTypeModifiable simpleType = attrInfo.getModifiableSimpleType();

IWDModifiableBinaryType binaryType =

(IWDModifiableBinaryType) simpleType;

binaryType.setFileName("TableData.xls");

binaryType.setMimeType(WDWebResourceType.XLS);

ByteArrayOutputStream outStr =

for (int Cntr = 0;Cntr < wdContext.nodeTableData().size();

Cntr++) {

wdContext.nodeTableData().moveTo(iCntr);

byte[] Part = new byte[74 * wdContext.nodeTableData().size()];

Part = wdContext.currentTableDataElement().getVal1().getBytes();

outStr.write(Part, 0,wdContext.currentTableDataElement().getVal1().length());

Part = wdContext.currentTableDataElement().getVal2().getBytes();

outStr.write(Part,0,wdContext.currentTableDataElement().getVal2().length());

}

wdContext.currentDownloadElement().setData(outStr.toByteArray());</i>

Regards

Sidharth Deshpande

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Sidharth,

Simply -- this is not an Excel format.

Try to use CSV (comma-separated value)

So your code

byte[] Part = new byte[74 * wdContext.nodeTableData().size()];
Part = wdContext.currentTableDataElement().getVal1().getBytes();
outStr.write(Part, 0,wdContext.currentTableDataElement().getVal1().length());
Part = wdContext.currentTableDataElement().getVal2().getBytes();
outStr.write(Part,0,wdContext.currentTableDataElement().getVal2().length());

becomes


byte[] NEW_LINE = "n".getBytes();
byte[] Part = wdContext.currentTableDataElement().getVal1().getBytes();
outStr.write( Part, 0, Part.length );
outStr.write((byte)';'); /* or outStr.write((byte)',')*/
Part = wdContext.currentTableDataElement().getVal2().getBytes();
outStr.write(Part, 0, part.length);
outStr.write( NEW_LINE, NEW_LINE.length );

Good luck,

VS

sid-desh
Advisor
Advisor
0 Kudos

Hi Valery,

It worked. Thanks a lot.

Regards

Sidharth

sid-desh
Advisor
Advisor
0 Kudos

Hi Valery,

Some time back you had given a solution to the Excel Download query. However now i have come acroos another problem.

Depending on the Locale of the user the Comma or the Semicolon has to be used as the list separator.

Any suggestions on how we can get the List Separator from the Regional Settings of the user who is running the WebDynpro Application.

Is such a thing supported in WebDynpro.

Regards

Sidharth

Former Member
0 Kudos

Not sure what you are trying to achieve and if it makes sense but you could do something like this:

Locale locale = Locale.US;

IWDClientUser curUser = WDClientUser.getCurrentUser();

if (curUser != null && curUser.getLocale() != null) {

locale = curUser.getLocale();

}

DecimalFormatSymbols dfs = new DecimalFormatSymbols(locale);

char separator = dfs.getDecimalSeparator();

Answers (3)

Answers (3)

MVar
Explorer
0 Kudos

Hello Sidharth,

I was looking at your Excel Download code and am wondering where the "data" value in IWDAttributeInfo attrInfo = wdContext.nodeDownload().getNodeInfo().getAttribute("data"); came from.

I am trying to create a download to excel functionality, but I get a null value in the attrInfo variable. For my purpose, I put the id of the table I am trying to download. (getAttribute("StkTable"))

Thanks in advance for your help.

Mike

Former Member
0 Kudos

Hi Siddharth/Valery

I am currently making the facility for end users to download data visible in the table to an excel sheet.

I am using an office control and binding a binary property to it

Then I have written a supply function for it which feeds it the data it requires using the above given method by urself

When I click on the button of down load excel. An excel file opens but it is completely blank .

Can you advice me what is the reason for that

Regards

Former Member
0 Kudos

Hi Guys

I am trying the same thing mentioned above. I have bound the data attibute shown above with an office intergration control.

Is that correct. From the code shown above your field must also be doing the same isnt it ?

Former Member
0 Kudos

Can I know to what this binary field of yours is bound ?