on 09-19-2011 12:19 PM
Hi SCN Experts,
So basically we are now able to upload our excel fil to a SAP Table. Thanks to you guys. Now, I would like to share our code on downloading the data in the table as an excel file. Can you tell us what's wrong with our code, since the popup window is not appearing thus we can not download the file, hence making it impossible to download the file. The codes that we used here were just sample codes that we found on the web that we modified a bit.
HI,
You can store the key values in LinkedHashMap object.
Create a LinkedHashMap in begin others code.
you can write the following Code in wdDoModifyView() to get the columns header values and store the key as context attrbute that is binded to the table cell editor.
fieldMap = new LinkedHashMap<String, String>();
IWDTable table = (IWDTable) view.getElement("Table Id");
if(table != null){
IWDAbstractTableColumn[] columns = table.getGroupedColumns();
String header = "";
String field = "";
for(int i=0;i<columns.length;i++)
{
IWDTableColumn col = (IWDTableColumn)columns<i>;
if(col.getVisible().equals(WDVisibility.VISIBLE))
{
header = col.getHeader().getText();
IWDTableCellEditor editor = col.getTableCellEditor();
if(!(editor instanceof IWDButton))
{
if(editor instanceof IWDTextView)
{
field = ((IWDTextView)editor).bindingOfText();
}
else if(editor instanceof IWDCheckBox)
{
field = ((IWDCheckBox)editor).bindingOfCheck();
}
else if(editor instanceof IWDInputField)
{
field = ((IWDInputField)editor).bindingOfValue();
}
fieldMap.put(field.substring(field.lastIndexOf(".")+1), header);
}
}
}
}Hope this helps you.
Regards,
Saleem Mohammad.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Team,
How can we count or get the number of columns and rows automatically from a web dynpro table so that we can download the table as is as an excel file. Is there a method or something like getcolumn/getrow. We're taking away the process of hardcoding in getting the columns and the rows. We found an article about using arrays but can you guys link us to a more complete guide on using arrays (for download to excel) here in web dynpro (java).
Thanks!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
Yes. We can get the count of number of Columns and Rows without hard coding the numbers..
If you tweak the Table Node properties, you can clearly understand that the
1. Columns in the table are the attributes in the Table Node and the count of attributes gives you the column count.
2. Size of the Table Node gives the row count of the table.
Regards,
Vijay.
Hi,
Yes. We can get the count of number of Columns and Rows without hard coding the numbers..
If you tweak the Table Node properties, you can clearly understand that the
1. Columns in the table are the attributes in the Table Node and the count of attributes gives you the column count.
2. Size of the Table Node gives the row count of the table.
Regards,
Vijay.
try{
// IWDCachedWebResource cachedExcelResource = null;
String fileName = "DownloadExcel.xls";
File f = new File(fileName);
WritableWorkbook wb = Workbook.createWorkbook(f);
WritableSheet sh = wb.createSheet("Name And Address", 0);
int columns = sh.getColumns();
int rows = sh.getRows();
int xn_row = 0;
String headerTitle[] = {"Name","Address"};
String headerFormat[] = {"C", "C"};
WritableFont tahoma9font = new WritableFont(WritableFont.TAHOMA, 9);
tahoma9font.setBoldStyle(tahoma9font.BOLD);
WritableCellFormat cellFormat = new WritableCellFormat();
cellFormat.setFont(tahoma9font);
cellFormat.setWrap(false);
cellFormat.setAlignment(Alignment.CENTRE);
for(int i = 0; i < headerTitle.length; i++){
cellFormat = new WritableCellFormat();
tahoma9font = new WritableFont(WritableFont.TAHOMA, 9);
tahoma9font.setBoldStyle(tahoma9font.BOLD);
cellFormat.setFont(tahoma9font);
cellFormat.setAlignment(Alignment.LEFT);
cellFormat.setWrap(false);
Label h = new Label(i, 0, headerTitle<i>, cellFormat);
sh.addCell(h);
WritableCell cell = sh.getWritableCell(i, 0);
}
sh.setColumnView(0, 20);
sh.setColumnView(1, 50);
//** Detail Node **//
IMainExcelDataNode nodeMainExcelData = wdContext.nodeMainExcelData();
// List CaseSummary = wdContext.currentShippingDataElement().getShippingCaseList();
// ** Loop from detail data ** //
for(int i = 0; i < nodeMainExcelData.size(); i++){
IMainExcelDataElement mainExcelDataElementAt = nodeMainExcelData.getMainExcelDataElementAt(i);
cellFormat = new WritableCellFormat();
tahoma9font = new WritableFont(WritableFont.TAHOMA, 9);
cellFormat.setFont(tahoma9font);
cellFormat.setAlignment(Alignment.CENTRE);
cellFormat.setWrap(false);
Label c0 = new Label(0, xn_row+1, mainExcelDataElementAt.getName(), cellFormat);
sh.addCell(c0);
c0 = new Label(1, xn_row+1, mainExcelDataElementAt.getAddress(), cellFormat);
sh.addCell(c0);
xn_row = xn_row + 1;
}
wb.write();
wb.close();
FileInputStream excelCSVFile = new FileInputStream(f);
IWDResource cachedExcelResource = WDResourceFactory.createCachedResource(excelCSVFile, fileName, WDWebResourceType.XLS, false);
// String url = cachedExcelResource.getUrl(WDFileDownloadBehaviour.OPEN_INPLACE.ordinal());
// FileInputStream excelCSVFile = new FileInputStream(f);
// IWDCachedWebResource cachedWebResource = null;
// cachedWebResource = WDWebResource.getWebResource(excelCSVFile, WDWebResourceType.XLS);
// cachedWebResource.setResourceName(fileName);
// String url = cachedWebResource.getUrl(WDFileDownloadBehaviour.ALLOW_SAVE.ordinal());
IWDWindow window =
wdComponentAPI
.getWindowManager()
.createNonModalExternalWindow(
cachedExcelResource.getUrl(
WDFileDownloadBehaviour.OPEN_INPLACE.ordinal()),
cachedExcelResource.getResourceName());
window.show();
// IWDWindow window =
// wdThis.wdGetAPI().getComponent().getWindowManager().createNonModalExternalWindow(
// url,
// "TD Netweaver Application");
// window.removeWindowFeature(WDWindowFeature.MENU_BAR);
// window.removeWindowFeature(WDWindowFeature.TOOL_BAR);
// window.removeWindowFeature(WDWindowFeature.ADDRESS_BAR);
// window.removeWindowFeature(WDWindowFeature.STATUS_BAR);
// window.show();
}catch (Exception e){
msgManager.reportException("Error: " + e);
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
Please Check this code...By using this code u can File SAVE popup window will be appering.
public void downloadToExcel( )
{
String fileName = "Customer" + ".xls";
IWDCachedWebResource cachedExcelResource = null;
try
{
File f = new File("Customer.xls");
WritableWorkbook workbook = Workbook.createWorkbook(f);
WritableFont black = new WritableFont(WritableFont.createFont("Trebuchet MS"),WritableFont.DEFAULT_POINT_SIZE,WritableFont.BOLD,false,UnderlineStyle.SINGLE,Colour.BLACK);
WritableCellFormat blackFormat = new WritableCellFormat(black);
WritableFont blue = new WritableFont(WritableFont.createFont("Trebuchet MS"),WritableFont.DEFAULT_POINT_SIZE,WritableFont.NO_BOLD,false,UnderlineStyle.NO_UNDERLINE,Colour.BLUE);
WritableCellFormat blueFormat = new WritableCellFormat(blue);
WritableSheet sheet = workbook.createSheet("Customer", 0);
Label label;
String[] header={"Corporate Code","Batch ID"};
for (int i=0;i<2;i++)
{
label = new Label(i,0,header<i>.toString(),blackFormat);
sheet.addCell(label);
}
WritableCellFormat integerFormat = new WritableCellFormat(NumberFormats.INTEGER);
jxl.write.Number number;
// Reading the contents
for(int i=0;i<wdContext.nodeVn_DownloadToExcel().size();i++)
{
String strCorpName = wdContext.currentContextElement().getVa_CorpCode();
String strBatchID = wdContext.nodeVn_DownloadToExcel().getVn_DownloadToExcelElementAt(i).getVa_BatchID();
label = new Label(0,i+1,strCorpName,blueFormat);
sheet.addCell(label);
label = new Label(1,i+1,strBatchID,blueFormat);
sheet.addCell(label);
}
workbook.setColourRGB(Colour.LIME, 0xff, 0, 0);
workbook.write();
FileInputStream excelCSVFile = new FileInputStream(f);
IWDCachedWebResource cachedWebResource = null;
if (excelCSVFile!= null)
{
cachedWebResource = WDWebResource.getWebResource(excelCSVFile, WDWebResourceType.getWebResourceType("xls","application/ms-excel"));
cachedWebResource.setResourceName(fileName);
}
cachedExcelResource = cachedWebResource;
wdContext.currentContextElement().setVa_DownloadToExcel(cachedExcelResource.getURL());
workbook.close();
}
catch (Exception ex)
{
wdComponentAPI.getMessageManager().reportException("Error in Excel Download"+ex.getMessage(),false);
}
Hope this helps!!
Thanks & Regards
Vijay K
Edited by: VijaySAPEP on Sep 19, 2011 6:07 PM
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.