cancel
Showing results for 
Search instead for 
Did you mean: 

Problem in adding external jar to DC

Former Member
0 Kudos

Hi,

I followed the following blogs

to add an external jar to a dc.

I was able to create the jar successfully.But i have a problem in adding those jars to DC.

I checked out one DC from track A and when I go to DC Metadata-DC Definition-Used Dc and right click and I can see only the DCs which are there in the track A.

Does blog mentions only we can add jars only to local webdynpro DCs ?

Please let me know the solution of adding exteranl jars to DC from a track

Thanks

Bala Duvvuri

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Bala,

Did you look below reference

Koti Reddy

Answers (2)

Answers (2)

Former Member
0 Kudos

hi bala,

1.go in DC meta data/DC definations/used dcs.

2.right click on used DC's.select ADD used DC's.

3.you will see many traks.you have to find your jar files in that and u have to add.

(i found my jar file in sap.com.SAP-JEE_1)

i was strugling with same problem .but after this i was solved and it was working fine.

jayesh talreja.

(if helpull please revart point)

Former Member
0 Kudos

Thanks for the inputs.

I will try them over the weekend and get back to you if i still have issues

Thanks

Bala Duvvuri

Former Member
0 Kudos

Hi,

I was able to add external jar successfully and able to generate an excel sheet using the following code

public void exportToExcel2003( com.sap.tc.webdynpro.progmodel.api.IWDNode dataNode, java.util.Map columnInfos )

{

//@@begin exportToExcel2003()

byte[] excelXMLFile;

IWDCachedWebResource cachedExcelResource = null;

//String fileName = dataNode.getNodeInfo().getName() + ".xls";

String fileName = "SalaryData.xls";

try {

// create Excel 2003 XML data as a byte array for the given context node,

// attributes and headers

excelXMLFile = CreateExcel(dataNode, columnInfos).getBytes();

// POIFSFileSystem fs = new POIFSFileSystem(

// new FileInputStream(

// fileName));

// HSSFWorkbook wb = new HSSFWorkbook(fs);

// // get a reference to the worksheet

// HSSFSheet sheet = wb.getSheetAt(0);

// InputStream is = new FileInputStream(CreateExcel(dataNode, columnInfos).getBytes());

// HSSFWorkbook.

// create a cached Web Dynpro XLS resource for the given byte array

// and filename

cachedExcelResource = getCachedWebResource(

excelXMLFile, fileName, WDWebResourceType.XLS);

// Store URL and file name of cached Excel resource in context.

if (cachedExcelResource != null) {

wdContext.currentContextElement().setExcelFileURL(

cachedExcelResource.getURL());

//wdComponentAPI.getMessageManager().reportSuccess("inside"+cachedExcelResource.getURL());

wdContext.currentContextElement().setExcelFileName(

cachedExcelResource.getResourceName());

// wdContext.currentContextElement().setExcelFileName(

// "SalaryData.xls");

//wdComponentAPI.getMessageManager().reportSuccess("inside"+cachedExcelResource.getResourceName());

// Open popup window with a link to the cached Excel file Web resource.

openExcel();

} else {

wdComponentAPI.getMessageManager().reportException(

"Failed to create Excel file from table!", true);

}

}

// catch (UnsupportedEncodingException e) {

// wdComponentAPI.getMessageManager().reportException(

// e.getLocalizedMessage(), true);

// }

catch (WDURLException e) {

wdComponentAPI.getMessageManager().reportException(

e.getLocalizedMessage(), true);

}

//@@end

}

private HSSFWorkbook CreateExcel(IWDNode dataNode, Map mHeaders)

{

IWDMessageManager msgManager = wdComponentAPI.getMessageManager();

FileOutputStream fileContacts = null;

HSSFWorkbook oBook = null;

try

{

// Create the File

fileContacts = new FileOutputStream("SalaryData.xls");

oBook = new HSSFWorkbook();

oBook = PopulateExcel(oBook,dataNode,mHeaders);

oBook.setSheetName(0,"SalaryData");

try

{

//oBook.setActiveSheet(0);

oBook.write(fileContacts);

fileContacts.close();

}

catch (IOException ex)

{

msgManager.reportException(ex.getLocalizedMessage(), true);

}

}

catch (FileNotFoundException e)

{

msgManager.reportException(e.getLocalizedMessage(), true);

}

catch(Exception e){

}

return oBook;

}

private HSSFWorkbook PopulateExcel(HSSFWorkbook oBook,IWDNode dataNode, Map mHeaders)

{

IWDMessageManager msgManager = wdComponentAPI.getMessageManager();

// Create a new sheet

HSSFSheet oSheet = oBook.createSheet();

oBook.setSheetName(0,"Salary Data");

// Declare a row object reference and Counting Variable

HSSFRow oRow = null;

int iRow = 0;

// Declare a cell object reference

HSSFCell oCell = null;

// Create create cell styles

HSSFCellStyle csHeaders = oBook.createCellStyle();

HSSFCellStyle csNormal = oBook.createCellStyle();

HSSFCellStyle csLastRow = oBook.createCellStyle();

HSSFCellStyle csLegend = oBook.createCellStyle();

HSSFCellStyle csDisclaimer = oBook.createCellStyle();

HSSFDataFormat df = oBook.createDataFormat();

// Create create fonts objects

HSSFFont fHeaders = oBook.createFont();

HSSFFont fNormal = oBook.createFont();

HSSFFont fFine = oBook.createFont();

// Set Header Font properties

fHeaders.setFontHeightInPoints((short) 12);

fHeaders.setColor( (short)HSSFColor.WHITE.index);

fHeaders.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);

// Set Normal Font properties

fNormal.setFontHeightInPoints((short) 10);

fNormal.setColor( (short)HSSFFont.COLOR_NORMAL );

fNormal.setBoldweight(HSSFFont.BOLDWEIGHT_NORMAL);

// Set Fine Print Font properties

fFine.setFontHeightInPoints((short) 8);

fFine.setColor( (short)HSSFFont.COLOR_NORMAL );

fFine.setBoldweight(HSSFFont.BOLDWEIGHT_NORMAL);

fFine.setItalic(true);

// Assign Styles to Header Cells

csHeaders.setFont(fHeaders);

csHeaders.setBorderBottom(csHeaders.BORDER_THICK);

csHeaders.setBorderTop(csHeaders.BORDER_THICK);

csHeaders.setBorderRight(csHeaders.BORDER_THIN);

csHeaders.setBorderLeft(csHeaders.BORDER_THIN);

csHeaders.setFillPattern((short) HSSFCellStyle.SOLID_FOREGROUND);

csHeaders.setFillForegroundColor((short)HSSFColor.LIGHT_BLUE.index);

csHeaders.setAlignment(HSSFCellStyle.ALIGN_CENTER);

// Assign Styles to Normal Cells

csNormal.setFont(fNormal);

csNormal.setBorderBottom(csNormal.BORDER_THIN);

csNormal.setBorderTop(csNormal.BORDER_THIN);

csNormal.setBorderRight(csNormal.BORDER_THIN);

csNormal.setBorderLeft(csNormal.BORDER_THIN);

// Assign Style for Last Data Row

csLastRow.setBorderBottom(csLastRow.BORDER_THICK);

csLastRow.setBorderTop(csLastRow.BORDER_THIN);

csLastRow.setBorderRight(csLastRow.BORDER_THIN);

csLastRow.setBorderLeft(csLastRow.BORDER_THIN);

// Assign Style to Legend and Disclaimer Cells

csLegend.setFont(fFine);

csLegend.setAlignment(HSSFCellStyle.ALIGN_RIGHT);

csDisclaimer.setFont(fFine);

csDisclaimer.setAlignment(HSSFCellStyle.ALIGN_CENTER);

// Create a Header Row

oRow = oSheet.createRow(iRow);

// Set and Populate the Header Cells

short iHeaderCell = 0;

int iColumns = mHeaders.size();

String[] aHeaders = new String[iColumns];

for (Iterator iter = mHeaders.keySet().iterator(); iter.hasNext();)

{

oCell = oRow.createCell(iHeaderCell);

aHeaders[iHeaderCell]=(String) iter.next();

oCell.setCellValue(new HSSFRichTextString(aHeaders[iHeaderCell]));

//oCell.setCellValue(aHeaders[iHeaderCell]);

oCell.setCellStyle(csHeaders);

iHeaderCell++;

}

// Set and Populate the Data Cells

int iElement = 0; //Start counting node Elements at 0

String sValue="";

for (iRow = 1; iRow <= dataNode.size(); iRow++)

{

// Create a row for the element

oRow = oSheet.createRow(iRow);

// Create cells needed to display the attributes

IWDNodeElement ePerson = dataNode.getElementAt(iElement);

for (short stCell = 0; stCell < iColumns; stCell++)

{

oCell = oRow.createCell(stCell);

oCell.setCellType(1);

// Set Value to print

sValue = ePerson.getAttributeValue(aHeaders[stCell]).toString();

if (sValue.length()>0)

{

oCell.setCellValue(new HSSFRichTextString(sValue));

//oCell.setCellValue(sValue);

}

else

{

oCell.setCellValue(new HSSFRichTextString(" "));

//oCell.setCellValue(" ");

}

// Create borders

if (iRow<dataNode.size())

{

oCell.setCellStyle(csNormal);

}

else

{

oCell.setCellStyle(csLastRow);

}

}

iElement++;

}

// Create a Row to Display the Legend

oRow = oSheet.createRow(iRow);

oCell = oRow.createCell((short)0);

oCell.setCellValue(new HSSFRichTextString("Salary Data"));

//oCell.setCellValue("Salary Data");

oCell.setCellStyle(csLegend);

oSheet.addMergedRegion(new Region(iRow,(short)0,iRow,(short)(iColumns-1)));

// Advance two rows and display the Disclaimer

iRow = iRow+2;

oRow = oSheet.createRow(iRow);

oCell = oRow.createCell((short)0);

oCell.setCellValue(new HSSFRichTextString("Salary Data"));

//oCell.setCellValue("Salary Data");

oCell.setCellStyle(csDisclaimer);

oSheet.addMergedRegion(new Region(iRow,(short)0,iRow,(short)(iColumns-1)));

for (short iColumn = 0; iColumn < iColumns; iColumn++)

{

// Size the Columns to fit the contents

if (aHeaders[iColumn].equals("Email"))

{

oSheet.setColumnWidth(iColumn,(short)10000);

}

else

{

oSheet.setColumnWidth(iColumn,(short)7000);

}

}

return oBook;

}

but problem is when i open the excel sheet it says Lost document summary information

Please let me know how to resolve this issue

Thanks

Bala Duvvuri

Former Member
0 Kudos

Hi All,

can somebody send me the solution

Thanks

Bala Duvvuri

former_member192434
Active Contributor
0 Kudos