Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Java API
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Jeanne Boyarsky
Ron McLeod
Paul Clapham
Liutauras Vilda
Sheriffs:
paul wheaton
Rob Spoor
Devaka Cooray
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Carey Brown
Frits Walraven
Tim Moores
Bartenders:
Mikalai Zaikin
Forum:
Other JSE/JEE APIs
Reading/Writing Data in excel using Apache POI
Vatsal Upadhyaya
Greenhorn
Posts: 18
I like...
posted 9 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.util.Date; 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.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.Row; import org.apache.poi.ss.usermodel.Sheet; import org.apache.poi.ss.usermodel.Workbook; import org.apache.poi.ss.usermodel.WorkbookFactory; public class PoiReadExcelFile { @SuppressWarnings("deprecation") public static void main(String[] args) throws Exception { Date dt=new Date(); int date=dt.getDate(); int month=dt.getMonth(); readSheet(date); } @SuppressWarnings("deprecation") public static void readSheet(int date){ int param=date+4; FileInputStream fileInputStream=null; try { fileInputStream = new FileInputStream("Enter Workbook To Be Read"); } catch (FileNotFoundException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } HSSFWorkbook workbook=null; try { workbook = new HSSFWorkbook(fileInputStream); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } HSSFSheet worksheet = workbook.getSheet("Sheet to be read"); HSSFRow row = worksheet.getRow(param);//if param is 0 , it means it is pointing to column A and so on HSSFCell cell=row.getCell((short)22); String Val = cell.getStringCellValue(); try { writeSheets(1, date, Val); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } public static void writeSheets(int param,int date,String value) throws Exception{ int rowCal=date+1; FileInputStream fileIn = null; Row row=null; Cell cell=null; try { fileIn = new FileInputStream("Workbook to be written"); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } Workbook workbook1=WorkbookFactory.create(fileIn); Sheet sheet1=workbook1.getSheet("Sheet to be written"); if (param==1) { row=sheet1.getRow(2); cell=row.createCell(rowCal); cell.setCellValue(value); } if (param==3) { row=sheet1.getRow(7); cell=row.createCell(rowCal); cell.setCellValue(value); } fileIn.close(); FileOutputStream fileOut=new FileOutputStream("Workbook to be written"); workbook1.write(fileOut); fileOut.close(); } }
Avenger
Ulf Dittmer
Rancher
Posts: 43081
77
posted 9 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Do you have a question about this?
Did you see how Paul
cut 87% off of his electric heat bill with 82 watts of micro heaters
?
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
Writing in existing excel(.xls) file
read an .xslx (excel) file with java. i get an error file not found
transfer data between Excel sheets
Reading & writing to Excel spreadsheets
Using JXL to edit an existing excel sheet withe new data
More...