I have installed/integrated poi in to my project version (2.5 final) and yet I keep getting this error
import org.apache.poi.hdf.extractor.WordDocument;
cannot be resolved...and thus it won't let me do any more compiling...
I am so confused as to y it is not working...this is the ONLY error I have [or that shows up in eclipse] - help please?
below is my code --- btw steal if u wish...just help me fix my error in return...Thanks!
~Divya
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStreamReader;
import java.io.Reader;
import java.io.StringWriter;
import java.util.Iterator;
import javax.swing.text.DefaultStyledDocument;
import javax.swing.text.rtf.RTFEditorKit;
import org.apache.lucene.document.DateField;
import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field;
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.hdf.extractor.WordDocument;
public class MsFileDocument {
private static final char FILE_SEPARATOR =
System.getProperty("file.separator").charAt(0);
MsFileDocument() {
}
public static Document getDocument(File file)
throws FileNotFoundException {
String fileName = file.getName().toLowerCase();
FileInputStream fis = new FileInputStream(file);
Reader reader = new BufferedReader(new InputStreamReader(fis));
int len;
Document doc = new Document();
String uid =
file.getPath().replace(FILE_SEPARATOR, '\u0000')
+ "\u0000"
+ DateField.timeToString(file.lastModified());
doc.add(new Field("uid", uid, false, true, false));
String contents = null;
if (fileName.endsWith(".doc")) {
try {
WordDocument wordDocument = new WordDocument(fis);
StringWriter stringWriter = new StringWriter();
wordDocument.writeAllText(stringWriter);
contents = stringWriter.toString();
stringWriter.close();
} catch (Exception e) {
System.out.println(e.getMessage());
}
} else if (fileName.endsWith(".rtf")) {
try {
DefaultStyledDocument dsd = new DefaultStyledDocument();
RTFEditorKit rtfEditorKit = new RTFEditorKit();
rtfEditorKit.read(reader, dsd, 0);
contents = dsd.getText(0, dsd.getLength());
} catch (Exception e) {
System.out.println(e.getMessage());
}
} else if (fileName.endsWith(".xls")) {
try {
contents = xlsTextStripper(fis);
} catch (Exception e) {
System.out.println(e.getMessage());
}
}
doc.add(Field.UnIndexed("path", file.getPath()));
//doc.add(Field.Text("file name", fileName));
doc.add(
Field.UnIndexed(
"url",
file.getPath().replace(FILE_SEPARATOR, '/')));
if (contents != null) {
doc.add(Field.Text("contents", contents));
} else {
doc.add(Field.Text("contents", reader));
}
doc.add(Field.UnIndexed("path", file.getPath()));
doc.add(
Field.Keyword(
"ModificationDate",
DateField.timeToString(file.lastModified())));
if (contents.length() < 200) {
len = contents.length();
} else {
len = 200;
}
doc.add(Field.UnIndexed("summary", contents.substring(0, len)));
contents.length();
return doc;
}
public static String xlsTextStripper(FileInputStream fis) {
String content = null;
try {
StringBuffer sb = new StringBuffer();
HSSFWorkbook workbook = new HSSFWorkbook(fis);
int numOfSheets = workbook.getNumberOfSheets();
for (int i = 0; i < numOfSheets; i++) {
HSSFSheet sheet = workbook.getSheetAt(i);
Iterator rowIterator = sheet.rowIterator();
while (rowIterator.hasNext()) {
HSSFRow row = (HSSFRow) rowIterator.next();
Iterator cellIterator = row.cellIterator();
while (cellIterator.hasNext()) {
HSSFCell cell = (HSSFCell) cellIterator.next();
String cellStringValue = null;
if (cell.getCellType() == 4) {
boolean booleanValue = cell.getBooleanCellValue();
cellStringValue = Boolean.toString(booleanValue);
} else if (cell.getCellType() == 0) {
double doubleValue = cell.getNumericCellValue();
cellStringValue = Double.toString(doubleValue);
} else if (cell.getCellType() == 1) {
cellStringValue = cell.getStringCellValue();
}
if (cellStringValue != null) {
sb.append(cellStringValue);
sb.append("\t");
}
}
sb.append("\n");
}
}
content = sb.toString();
} catch (Exception e) {
e.printStackTrace();
}
return content;
}
}