• 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

Use Java to open a CSV file

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am truly a green horn to JAVA. I am trying use JAVA (JXL) to do the following:
1. Open a csv file in Excel that is located at "C:\\Test" (Could I treat this like an excel file to be opened with JXL?)
2. Check Cell A1
If A1 is empty, close the file and end the routine. If A1 is not empty, go to step 3.
3. Close the csv file and send an Outlook email to 3 people stating "Event is now happening"

I assume there is probably another API library needed to work with Microsoft Outlook

I have been using Netbeans

I appreciate any help!!!
Dave
 
Sheriff
Posts: 7125
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think you will like this (click me).
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't think that POI can handle CSV, can it? If it can - great, but if not, the https://coderanch.com/how-to/java/AccessingFileFormats page lists numerous CSV-specific libraries in the "Excel" section.
 
Knute Snortum
Sheriff
Posts: 7125
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ulf Dittmer wrote:I don't think that POI can handle CSV, can it?



You're probably right. I saw Excel and thought POI. A library specifically for CSV is better.
 
Bartender
Posts: 1810
28
jQuery Netbeans IDE Eclipse IDE Firefox Browser MySQL Database Chrome Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And you don't need any Outlook specific api to send email, just use the Java mail classes. Good tutorial here.
 
David Malkin
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am now using the following code to open and check to see if cell A1 is empty or not but get the following error from Netbeans:
run:
jxl.read.biff.BiffException: Unable to recognize OLE stream
at jxl.read.biff.CompoundFile.<init>(CompoundFile.java:116) at jxl.read.biff.CompoundFile.<init>(CompoundFile.java:116)
at jxl.read.biff.File.<init>(File.java:127)
at jxl.Workbook.getWorkbook(Workbook.java:221)
at jxl.Workbook.getWorkbook(Workbook.java:198)
at jxl_polling_open_csv.JXL_Polling_Open_csv.read(JXL_Polling_Open_csv.java:24)
at jxl_polling_open_csv.JXL_Polling_Open_csv.main(JXL_Polling_Open_csv.java:53)
BUILD SUCCESSFUL (total time: 3 seconds)

WHAT SHALL I DO???

Here is the code:
import java.io.File;
import java.io.IOException;

import jxl.Cell;
import jxl.CellType;
import jxl.Sheet;
import jxl.Workbook;
import jxl.read.biff.BiffException;

public class ReadExcel {

private String inputFile;

public void setInputFile(String inputFile) {
this.inputFile = inputFile;
}

public void read() throws IOException {
File inputWorkbook = new File(inputFile);
Workbook w;
try {
w = Workbook.getWorkbook(inputWorkbook);
// Get the first sheet
Sheet sheet = w.getSheet(0);
// Loop over first 10 column and lines

for (int j = 0; j < sheet.getColumns(); j++) {
for (int i = 0; i < sheet.getRows(); i++) {
Cell cell = sheet.getCell(j, i);
CellType type = cell.getType();
if (type == CellType.LABEL) {
System.out.println("I got a label "
+ cell.getContents());
}

if (type == CellType.NUMBER) {
System.out.println("I got a number "
+ cell.getContents());
}

}
}
} catch (BiffException e) {
e.printStackTrace();
}
}

public static void main(String[] args) throws IOException {
ReadExcel test = new ReadExcel();
test.setInputFile("c:/temp/lars.xls");
test.read();
}

}
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't think jxl can handle CSV files, either (the error message indicates that it expects an Excel file). Use one of the CSV libraries I pointed you to instead.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic