Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


HIMANSHU SETHIYA
conversion
1 Answer(s)      4 years and 9 months ago
Posted in : Java Beginners


how to convertor .xl to .pdf and .pdf to .xl and .mp4 to .mp3

Advertisement
View Answers

April 2, 2010 at 12:13 PM


Hi Friend,

Try the following code:

1)xls to pdf:

import java.io.*;
import java.util.*;
import com.lowagie.text.*;
import com.lowagie.text.html.HtmlWriter;
import com.lowagie.text.pdf.PdfWriter;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;

public class ConvertXLSToPDF {
public static void main( String [] args ) {
String fileName="C:\\excelFile.xls";
Vector dataHolder=ConvertXLSToPDF(fileName);
printCellDataToConsole(dataHolder);
}
public static Vector ConvertXLSToPDF(String fileName){
Vector cellVectorHolder = new Vector();
try{
FileInputStream myInput = new FileInputStream(fileName);
POIFSFileSystem myFileSystem = new POIFSFileSystem(myInput);
HSSFWorkbook myWorkBook = new HSSFWorkbook(myFileSystem);
HSSFSheet mySheet = myWorkBook.getSheetAt(0);
Iterator rowIter = mySheet.rowIterator();
while(rowIter.hasNext()){
HSSFRow myRow = (HSSFRow) rowIter.next();
Iterator cellIter = myRow.cellIterator();
Vector cellStoreVector=new Vector();
while(cellIter.hasNext()){
HSSFCell myCell = (HSSFCell) cellIter.next();
cellStoreVector.addElement(myCell);
}
cellVectorHolder.addElement(cellStoreVector);
}
}catch (Exception e){e.printStackTrace(); }
return cellVectorHolder;
}
private static void printCellDataToConsole(Vector dataHolder) {
try{
Document document=new Document();
PdfWriter.getInstance(document,new FileOutputStream("file.pdf"));
document.open();
StringBuffer sb=new StringBuffer();
for (int i=1;i<dataHolder.size(); i++){
Vector cellStoreVector=(Vector)dataHolder.elementAt(i);
for (int j=0; j < cellStoreVector.size();j++){
HSSFCell myCell = (HSSFCell)cellStoreVector.elementAt(j);
String stringCellValue = myCell.toString()+" ";
sb.append(stringCellValue);
}

}
document.add(new Paragraph(sb.toString()));

document.close();

}
catch(Exception e){}
}
}


Related Tutorials/Questions & Answers:
conversion Applet
conversion Applet  I am a java beginner.................. strong texthow to create JApplet that prompts the user to enter a distance in miles in a JTextField and then converts mile to kilometers and display the result as XX.XX
currency conversion
currency conversion   hi frds.. I wan jsp code to convert currency in different formats??... if u know plz plz plz post it   Please visit the following link: http://www.roseindia.net/tutorials/I18N/currency
Advertisements
image conversion tools
image conversion tools  how many tools are available in image conversion at particularlly in java
.wav file conversion
.wav file conversion   how to read .wav file and converd the data into text format
Number conversion in JavaScript
Number conversion in JavaScript  How do you convert numbers between different bases in JavaScript
conversion of language in a project
conversion of language in a project  how can we convert the database code in the project dynamically
NSString to float conversion
NSString to float conversion  HI, I my iPhone and iPad application I have to convert NSString to float. Provide me example of NSString to float conversion. Thanks   Hi, Please see NSString to float conversion
object conversion - Java Beginners
object conversion   Hi, Can anybody tell me the object conversion in java.   Hi sandeep Can u please tell me in details about your.../java-conversion/ObjectToDouble.shtml Thanks... sandeep kumar suman
Conversion - Development process
is the theory of conversion from java to .NET? How it is done?   Hi... Conversion Assistant (JLCA). Code that calls Java APIs can convert to comparable C# code... to a topic with guidelines for modifications needed to finish the conversion
NSString to float conversion
NSString to float conversion  HI, I my iPhone and iPad application I have to convert NSString to float. Provide me example of NSString to float conversion. Thanks   HI, Use the following code: NSScanner *strXpos
Conversion of String to Integer
Conversion of String to Integer  public class Test { public static void main(String[] args) { int countA = 0; int countB = 0; int countC = 0; int countD = 0; int countE = 0; int
javascript integer to string conversion
javascript integer to string conversion  How to Javascript Integer to String Conversion   <script type="text/javascript"> /** * print out the value and the type of the variable passed
Java Conversion Question - Java Beginners
Java Conversion Question   Hello sir ,How i can Convert Java Code to Vb.net ,Plz Help Me
Distance conversion - Java Beginners
Distance conversion  Write an application that reads a distance in metres. The program will then present a user menu of conversion types, converting the distance to kilometres, feet and inches, according to the user?s selection
Data Conversion from double to another type
Data conversion is the conversion of data from one type to another type. In this section we will learn about data conversion from double primitive type to another data type like String, boolean and char etc
Data Conversion from long to another type
Data conversion is the conversion of data from one type to another type. In this section we will learn about data conversion from long primitive type to another data type like String, boolean and char etc
Data Conversion from float to another type
Data conversion is the conversion of data from one type to another type. In this section we will learn about data conversion from float primitive type to another data type like String, boolean and char etc
Data Conversion from short to another type
Data conversion is the conversion of data from one type to another type. In this section we will learn about data conversion from short primitive type to another data type like String, boolean and char etc
Data Conversion from byte to another type
Data conversion is the conversion of data from one type to another type. In this section we will learn about data conversion from byte primitive type to another data type like String, boolean and char etc
Data Conversion from int to another type
Data conversion is the conversion of data from one type to another type. In this section we will learn about data conversion from int primitive type to another data type like String, boolean and char etc
Data Conversion from String to another type
Data conversion is the conversion of data from one type to another type. In this section we will learn about data conversion from String primitive type to another data type like int, boolean and char etc
Excel conversion tool. - Java Beginners
Excel conversion tool.  Hi, I need a conversion tool which can convert .xls(Excel 2003) to .xlsx (Excel 2007) and vice-versa. Please suggest any links ro tools. Thank You
hexadecimal conversion java compilation - UML
hexadecimal conversion java compilation  write a simple program..., Please visit the following links: http://www.roseindia.net/java/java-conversion/BinaryToHexa.shtml http://www.roseindia.net/java/java-conversion
Data Conversion In Sql Server 2005
Data Conversion In Sql Server 2005  Hi I am working vb.net & sql server 2005 database. I am storing date (MM/DD/YYYY) format. now I have problem in sql date conversion (DD/MM/YYYY). Can you help how to convert date
Introduction to Type conversion in Struts
Introduction to Type conversion in Struts Type conversion is a mechanism... this powerful and important facility. In struts the type conversion is an mechanism... are converted into complex bean properties using this type conversion mechanism
Conversion of unicode to its corresponding character
Conversion of unicode to its corresponding character  i have a string of unicodes e.g String s="\c0059\c0049\c3000" .. i need code for converting these unicodes to its corresponding alphabets.. pls if possible rep asap as i need
Mysql Time Zone Conversion
Mysql Time Zone Conversion       The Tutorial illustrate you an example from 'Mysql Time Zone Conversion' that describes you about the time zone conversion. SYNTAX
String to Date Conversion - Java Beginners
  Hi friend, For conversion in this format : 11/SEP/2008 07:07:32...)); For read more information : http://www.roseindia.net/java/java-conversion
 

 

 

DMCA.com