0

The below is my code and I am facing (The type java.lang.CharSequence cannot be resolved. It is indirectly referenced from required .class files) error which will occur for myCell.setCellValue(value); statement.

import java.io.FileOutputStream;
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;

public class test3 {
    private static String dest = "D:\\testexcel.xls";
    private static HSSFWorkbook myWorkBook = new HSSFWorkbook();
    private static HSSFSheet mySheet = myWorkBook.createSheet();

    private static void excelLog(int row, int col, String value) {
        HSSFRow myRow = mySheet.getRow(row);

        if (myRow == null)
            myRow = mySheet.createRow(row);

        HSSFCell myCell = myRow.createCell(col);
        myCell.setCellValue(value);
    }

    public static void main(String[] args) {
        int numCol = 10; // assume 10 cols

        for (int i = 0; i < 10; i++) {
            for (int j = 0; j < numCol; j++) {
                excelLog(i, j, "Row : " + i + ", Cell : " + j);
            }
        }

        try {
            FileOutputStream out = new FileOutputStream(dest);
            myWorkBook.write(out);
            out.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
luk2302
  • 55,258
  • 23
  • 97
  • 137
WISAM
  • 21

1 Answers1

0

Most probably it is just an IDE build process related issue, code works perfect for org.apache.poi version 3.17.

  1. Please try to clean the project and build it once again.
  2. If it will not work delete the project from your IDE and import it once again - this should help.

As a quick check for this (in case of using build tool) - you can run build process from cmd and it should work.

marme1ad
  • 1,253
  • 8
  • 8
  • There is something similar [here >>](https://stackoverflow.com/questions/26167357/how-to-fix-the-type-java-lang-charsequence-cannot-be-resolved-it-is-indirectl) – marme1ad Sep 19 '18 at 20:25