ASG
IBM
Zystems
Cressida
Icon
Netflexity
 
  MQSeries.net
Search  Search       Tech Exchange      Education      Certifications      Library      Info Center      SupportPacs      LinkedIn  Search  Search                                                                   FAQ  FAQ   Usergroups  Usergroups
 
Register  ::  Log in Log in to check your private messages
 
RSS Feed - WebSphere MQ Support RSS Feed - Message Broker Support

MQSeries.net Forum Index » WebSphere Message Broker (ACE) Support » convert xls to text using msg broker

Post new topic  Reply to topic
 convert xls to text using msg broker « View previous topic :: View next topic » 
Author Message
RITCHEA
PostPosted: Thu Jul 28, 2011 1:34 am    Post subject: convert xls to text using msg broker Reply with quote

Apprentice

Joined: 25 Jul 2011
Posts: 27

hi...
I want to convert xls file to xml ... i m using java compute node .... it is giving n error (Type HSSFRow cannot be resolved to a type)...


i have used the code:-

import com.ibm.broker.javacompute.MbJavaComputeNode;
import com.ibm.broker.plugin.*;

import org.apache.poi.hssf.usermodel.*;
import org.w3c.dom.*;
import java.io.*;
import javax.xml.parsers.*;
import javax.xml.transform.*;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;


public class white_mf_JavaCompute extends MbJavaComputeNode {

public void evaluate(MbMessageAssembly contact admin) throws MbException {
MbOutputTerminal out = getOutputTerminal("out");
MbOutputTerminal alt = getOutputTerminal("alternate");

MbMessage inMessage = contact admin.getMessage();

// create new message
MbMessage outMessage = new MbMessage(inMessage);
MbMessageAssembly outAssembly = new MbMessageAssembly(contact admin,
outMessage);

try {
// ----------------------------------------------------------
// Add user code below

// End of user code
// ----------------------------------------------------------

// The following should only be changed
// if not propagating message to the 'out' terminal
out.propagate(outAssembly);

} finally {
// clear the outMessage
outMessage.clearMessage();
}
}


public void generateXML(File excelFile) {
try { //Initializing the XML document
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document document = builder.newDocument();
Element rootElement = document.createElement("incmstmts");
document.appendChild(rootElement);
//Creating top-level elements
Element stmtElement1 = document.createElement("stmt");
rootElement.appendChild(stmtElement1);

Element stmtElement2 = document.createElement("stmt");
rootElement.appendChild(stmtElement2);
//Adding first subelements
Element year1 = document.createElement("year");
stmtElement1.appendChild(year1);

year1.appendChild(document.createTextNode("2005")) ;

Element year2 = document.createElement("year");
stmtElement2.appendChild(year2);
year2.appendChild(document.createTextNode("2004")) ;
//Creating an HSSFSpreadsheet object from an Excel file
InputStream input = new FileInputStream(excelFile);
HSSFWorkbook workbook = new HSSFWorkbook(input);
HSSFSheet spreadsheet = workbook.getSheetAt(0);

for (int i = 1; i <= spreadsheet.getLastRowNum(); i++) {
switch (i) {
//Iterate over spreadsheet rows to create stmt element
//subelements.
case 1:
HSSFRow row1 = spreadsheet.getRow(1);

Element revenueElement1 = document.createElement("revenue");
stmtElement1.appendChild(revenueElement1);

revenueElement1.appendChild
(document.createTextNode
(row1.getCell((short) 1).
getStringCellValue()));

Element revenueElement2 = document.createElement("revenue");
stmtElement2.appendChild(revenueElement2);

revenueElement2.appendChild
(document.createTextNode
(row1.getCell((short) 2).
getStringCellValue()));

break;
case 2:
HSSFRow row2 = spreadsheet.getRow(2);

Element costofrevenue1 = document.createElement("costofrevenue");
stmtElement1.appendChild(costofrevenue1);
costofrevenue1.appendChild
(document.createTextNode
(row2.getCell((short)1).
getStringCellValue()));

Element costofrevenue2 = document.createElement("costofrevenue");
stmtElement2.appendChild(costofrevenue2);

costofrevenue2.appendChild
(document.createTextNode
(row2.getCell((short) 2).
getStringCellValue()));
break;
case 3:
HSSFRow row3 = spreadsheet.getRow(3);

Element researchdevelopment1 = document.createElement("researchdevelopment");
stmtElement1.appendChild(researchdevelopment1);

researchdevelopment1.appendChild
(document.createTextNode
(row3.getCell(1).getStringCellValue()));

Element researchdevelopment2 =document.createElement("researchdevelopment");
stmtElement2.appendChild(researchdevelopment2);

researchdevelopment2.appendChild
(document.createTextNode
(row3.getCell(2).
getStringCellValue()));
break;
case 4:
HSSFRow row4 = spreadsheet.getRow(4);

Element salesmarketing1 = document.createElement("salesmarketing");
stmtElement1.appendChild(salesmarketing1);

salesmarketing1.appendChild(document.createTextNode(row4.getCell(1).getStringCellValue()));

Element salesmarketing2 = document.createElement("salesmarketing");
stmtElement2.appendChild(salesmarketing2);
salesmarketing2.appendChild(document.createTextNode(row4.getCell(2).getStringCellValue()));
break;
case 5:
HSSFRow row5 = spreadsheet.getRow(5);

Element generaladmin1 = document.createElement("generaladmin");
stmtElement1.appendChild(generaladmin1);

generaladmin1.appendChild(document.createTextNode( row5
.getCell(1).getStringCellValue()));

Element generaladmin2 = document.createElement("generaladmin");
stmtElement2.appendChild(generaladmin2);

generaladmin2.appendChild(document.createTextNode( row5
.getCell((short) 2).getStringCellValue()));
break;
case 6:
HSSFRow row6 = spreadsheet.getRow(6);

Element totaloperexpenses1 = document.createElement("totaloperexpenses");
stmtElement1.appendChild(totaloperexpenses1);

totaloperexpenses1.appendChild(document.createTextNode(row6
.getCell((short) 1).getStringCellValue()));

Element totaloperexpenses2 = document.createElement("totaloperexpenses");
stmtElement2.appendChild(totaloperexpenses2);

totaloperexpenses2.appendChild(document.createTextNode(row6
.getCell((short) 2).getStringCellValue()));
break;
case 7:
HSSFRow row7 = spreadsheet.getRow(7);

Element operincome1 = document.createElement("operincome");
stmtElement1.appendChild(operincome1);

operincome1.appendChild(document.createTextNode(row7
.getCell((short) 1).getStringCellValue()));

Element operincome2 = document.createElement("operincome");
stmtElement2.appendChild(operincome2);

operincome2.appendChild
(document.createTextNode
(row7.getCell((short) 2).
getStringCellValue()));
break;
case 8:
HSSFRow row8 = spreadsheet.getRow(;

Element invincome1 = document.createElement("invincome");
stmtElement1.appendChild(invincome1);

invincome1.appendChild
(document.createTextNode
(row8.getCell((short) 1).
getStringCellValue()));

Element invincome2 = document.createElement("invincome");
stmtElement2.appendChild(invincome2);

invincome2.appendChild
(document.createTextNode
(row8.getCell((short) 2).
getStringCellValue()));
break;
case 9:
HSSFRow row9 = spreadsheet.getRow(9);

Element incbeforetaxes1 = document.createElement("incbeforetaxes");
stmtElement1.appendChild(incbeforetaxes1);

incbeforetaxes1.appendChild
(document.createTextNode
(row9.getCell((short) 1).
getStringCellValue()));

Element incbeforetaxes2 =document.createElement("incbeforetaxes");
stmtElement2.appendChild(incbeforetaxes2);

incbeforetaxes2.appendChild
(document.createTextNode
(row9.getCell((short)2).
getStringCellValue()));
break;
case 10:
HSSFRow row10 = spreadsheet.getRow(10);

Element taxes1 = document.createElement("taxes");
stmtElement1.appendChild(taxes1);

taxes1.appendChild(document.createTextNode(row10.getCell(
(short) 1).getStringCellValue()));

Element taxes2 = document.createElement("taxes");
stmtElement2.appendChild(taxes2);

taxes2.appendChild(document.createTextNode(row10.getCell(
(short) 2).getStringCellValue()));
break;

case 11:
HSSFRow row11 = spreadsheet.getRow(11);

Element netincome1 = document.createElement("netincome");
stmtElement1.appendChild(netincome1);

netincome1.appendChild(document.createTextNode(row11
.getCell((short) 1).getStringCellValue()));

Element netincome2 = document.createElement("netincome");
stmtElement2.appendChild(netincome2);

netincome2.appendChild(document.createTextNode(row11
.getCell((short) 2).getStringCellValue()));
break;
default:
break;
}

}

TransformerFactory tFactory = TransformerFactory.newInstance();

Transformer transformer = tFactory.newTransformer();
//Add indentation to output
transformer.setOutputProperty
(OutputKeys.INDENT, "yes");
transformer.setOutputProperty(
"{http://xml.apache.org/xslt}indent-amount", "2");

DOMSource source = new DOMSource(document);
StreamResult result = new StreamResult(System.out);
transformer.transform(source, result);
} catch (IOException e) {
System.out.println("IOException " + e.getMessage());
} catch (ParserConfigurationException e) {
System.out
.println("ParserConfigurationException " + e.getMessage());
} catch (TransformerConfigurationException e) {
System.out.println("TransformerConfigurationExcept ion "+ e.getMessage());
} catch (TransformerException e) {
System.out.println("TransformerException " + e.getMessage());
}
}

/* public static void main(String[] argv) {
white_mf_JavaComput excel = new white_mf_JavaComput();
File input = new File("C:\\Excel\\CC1.xls");
excel.generateXML(input);
} */
}



Back to top
View user's profile Send private message
WMBDEV1
PostPosted: Thu Jul 28, 2011 4:04 am    Post subject: Reply with quote

Sentinel

Joined: 05 Mar 2009
Posts: 888
Location: UK

Is it giving the error in the toolkit or in the broker?

How have you deployed / referenced the Jars that are needed?

Can you and sandip_gaikwad please stop posting the same questions. Its annoying
Back to top
View user's profile Send private message
Vitor
PostPosted: Thu Jul 28, 2011 4:12 am    Post subject: Reply with quote

Grand High Poobah

Joined: 11 Nov 2005
Posts: 26093
Location: Texas, USA

WMBDEV1 wrote:
Can you and sandip_gaikwad please stop posting the same questions. Its annoying


More interesting is that this and all their other posts are posted from the same IP address.

I've speculated before that it's the same person with 2 IDs. Well, 3 IDs, all created within a day of each other, all asking similar questions.

And don't use c o d e tags so you can read things.
_________________
Honesty is the best policy.
Insanity is the best defence.
Back to top
View user's profile Send private message
lancelotlinc
PostPosted: Thu Jul 28, 2011 4:27 am    Post subject: Reply with quote

Jedi Knight

Joined: 22 Mar 2010
Posts: 4941
Location: Bloomington, IL USA

Vitor wrote:
WMBDEV1 wrote:
Can you and sandip_gaikwad please stop posting the same questions. Its annoying


More interesting is that this and all their other posts are posted from the same IP address.

I've speculated before that it's the same person with 2 IDs. Well, 3 IDs, all created within a day of each other, all asking similar questions.

And don't use c o d e tags so you can read things.


It's some reverse psychology, eh Sir Vitor?
_________________
http://leanpub.com/IIB_Tips_and_Tricks
Save $20: Coupon Code: MQSERIES_READER
Back to top
View user's profile Send private message Send e-mail
Vitor
PostPosted: Thu Jul 28, 2011 4:31 am    Post subject: Reply with quote

Grand High Poobah

Joined: 11 Nov 2005
Posts: 26093
Location: Texas, USA

lancelotlinc wrote:
It's some reverse psychology, eh Sir Vitor?


It's potentially counter-productive and borderline spamming.

Unlike your personal crusades which at least have some higher purpose. And have been refreshingly scaled back in recent days.
_________________
Honesty is the best policy.
Insanity is the best defence.
Back to top
View user's profile Send private message
lancelotlinc
PostPosted: Thu Jul 28, 2011 4:45 am    Post subject: Reply with quote

Jedi Knight

Joined: 22 Mar 2010
Posts: 4941
Location: Bloomington, IL USA

Vitor wrote:
lancelotlinc wrote:
It's some reverse psychology, eh Sir Vitor?


It's potentially counter-productive and borderline spamming.

Unlike your personal crusades which at least have some higher purpose. And have been refreshingly scaled back in recent days.


Well Sir Vitor, thank you ever so much for the nice complement.
_________________
http://leanpub.com/IIB_Tips_and_Tricks
Save $20: Coupon Code: MQSERIES_READER
Back to top
View user's profile Send private message Send e-mail
Vitor
PostPosted: Thu Jul 28, 2011 4:51 am    Post subject: Reply with quote

Grand High Poobah

Joined: 11 Nov 2005
Posts: 26093
Location: Texas, USA

lancelotlinc wrote:
Vitor wrote:
lancelotlinc wrote:
It's some reverse psychology, eh Sir Vitor?


It's potentially counter-productive and borderline spamming.

Unlike your personal crusades which at least have some higher purpose. And have been refreshingly scaled back in recent days.


Well Sir Vitor, thank you ever so much for the nice complement.


I strive for balance. Sometimes I may fail, but I strive.
_________________
Honesty is the best policy.
Insanity is the best defence.
Back to top
View user's profile Send private message
RITCHEA
PostPosted: Fri Jul 29, 2011 2:47 am    Post subject: Reply with quote

Apprentice

Joined: 25 Jul 2011
Posts: 27

my and his problem r different ... i m unable to use poi in java compute node... pls help if u can..
Back to top
View user's profile Send private message
smdavies99
PostPosted: Fri Jul 29, 2011 3:52 am    Post subject: Reply with quote

Jedi Council

Joined: 10 Feb 2003
Posts: 6076
Location: Somewhere over the Rainbow this side of Never-never land.

RITCHEA wrote:
my and his problem r different ... i m unable to use poi in java compute node... pls help if u can..


A polite request.

This is not an SMS forum. Proper English is the default language. 'r, poi, pls help if u' is jibberish for some of us, just like

пожалуйста помогите мне если вы можете?
or even
другая бутылка водочки и быстра о ей

is when spoken like a drunken sailor from Murmanskaya.
_________________
WMQ User since 1999
MQSI/WBI/WMB/'Thingy' User since 2002
Linux user since 1995

Every time you reinvent the wheel the more square it gets (anon). If in doubt think and investigate before you ask silly questions.
Back to top
View user's profile Send private message
Vitor
PostPosted: Fri Jul 29, 2011 4:09 am    Post subject: Reply with quote

Grand High Poobah

Joined: 11 Nov 2005
Posts: 26093
Location: Texas, USA

smdavies99 wrote:
is when spoken like a drunken sailor from Murmanskaya.


You were in that bar too???
_________________
Honesty is the best policy.
Insanity is the best defence.
Back to top
View user's profile Send private message
lancelotlinc
PostPosted: Fri Jul 29, 2011 5:05 am    Post subject: Reply with quote

Jedi Knight

Joined: 22 Mar 2010
Posts: 4941
Location: Bloomington, IL USA

smdavies99 wrote:
This is not an SMS forum. Proper English is the default language.


At least he stopped posting his Facebook status.
_________________
http://leanpub.com/IIB_Tips_and_Tricks
Save $20: Coupon Code: MQSERIES_READER
Back to top
View user's profile Send private message Send e-mail
mqjeff
PostPosted: Fri Jul 29, 2011 5:13 am    Post subject: Reply with quote

Grand Master

Joined: 25 Jun 2008
Posts: 17447

smdavies99 wrote:
Proper English is the default language.


Sorry mate, most of us just use American.
Back to top
View user's profile Send private message
Vitor
PostPosted: Fri Jul 29, 2011 5:17 am    Post subject: Reply with quote

Grand High Poobah

Joined: 11 Nov 2005
Posts: 26093
Location: Texas, USA

mqjeff wrote:
smdavies99 wrote:
Proper English is the default language.


Sorry mate, most of us just use American.


At least you spell out the words. Most of them correctly.
_________________
Honesty is the best policy.
Insanity is the best defence.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic  Reply to topic Page 1 of 1

MQSeries.net Forum Index » WebSphere Message Broker (ACE) Support » convert xls to text using msg broker
Jump to:  



You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Protected by Anti-Spam ACP
 
 


Theme by Dustin Baccetti
Powered by phpBB © 2001, 2002 phpBB Group

Copyright © MQSeries.net. All rights reserved.