Avatar of sadaf_syed
sadaf_syed asked on

get 2 java error please help

i get these two java errors:
s
D:\java_src\RMARepair\src\RMARepairs\RMARepairs.java:649: createRow(short) in org.apache.poi.hssf.usermodel.HSSFSheet cannot be applied to (int)
    HSSFRow row = sheet.createRow(0);
D:\java_src\RMARepair\src\RMARepairs\RMARepairs.java:661: createRow(short) in org.apache.poi.hssf.usermodel.HSSFSheet cannot be applied to (int)
        row = sheet.createRow(rowCnt);
private HSSFWorkbook createSpreadsheet(StringBuffer a_sb){
    char[] c = a_sb.toString().toCharArray();
    
    HSSFWorkbook workbook = new HSSFWorkbook();
    HSSFSheet sheet = workbook.createSheet("RMA Repairs");
    HSSFRow row = sheet.createRow(0);
    HSSFCell cell = row.createCell((short)0);
    
    int rowCnt = 0;
    short colCnt = 0;
    for (int i = 0; i < c.length; i++){
      if (c[i] == '\n'){
        if (isNumeric(cell.getStringCellValue())){
          cell.setCellValue(Double.valueOf(cell.getStringCellValue()).doubleValue());
        }
        
        rowCnt++;
        row = sheet.createRow(rowCnt);
        colCnt = 0;
        cell = row.createCell(colCnt);
      }
      else if (c[i] == (char)9){
        if (isNumeric(cell.getStringCellValue())){
          cell.setCellValue(Double.valueOf(cell.getStringCellValue()).doubleValue());
        }
        
        colCnt++;
        cell = row.createCell(colCnt);
      }
      else{
        cell.setCellValue(cell.getStringCellValue() + c[i]);
      }
    }
    
   
    return workbook;

Open in new window

Java

Avatar of undefined
Last Comment
sciuriware

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
sciuriware

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Jim Cakalic

Per Java syntax rules, methods that take a primitive numeric argument will automatically cast an argument value that is a smaller primitive type because the destination type can hold larger values than the source but an explict cast is required when the destination type (short in this case) is smaller than the source (int) because the value could possibly be truncated at runtime. The compiler requires that you explicitly state your intention by supplying the cast.
Please do not accept this answer as the solution as sciuriware's answer is correct.
Regards
sciuriware

Thanks, where have you been all that time?

;JOOP!
bluebelldiscovery

You might want to use the latest version of POI 3.2
http://www.apache.org/dyn/closer.cgi/poi/release/

public HSSFCell createCell(short columnIndex)
has been deprecated.
http://poi.apache.org/apidocs/org/apache/poi/hssf/usermodel/HSSFRow.html#createCell(short) 

If you are using POI 3.2 the following will work for u.

Change 1
    HSSFCell cell = row.createCell((short)0);
to
    HSSFCell cell = row.createCell(0);

Change 2
    short colCnt = 0;
to
    int colCnt = 0;

private HSSFWorkbook createSpreadsheet(StringBuffer a_sb){
    char[] c = a_sb.toString().toCharArray();
    
    HSSFWorkbook workbook = new HSSFWorkbook();
    HSSFSheet sheet = workbook.createSheet("RMA Repairs");
    HSSFRow row = sheet.createRow(0);
    HSSFCell cell = row.createCell(0);
    
    int rowCnt = 0;
    int colCnt = 0;
    for (int i = 0; i < c.length; i++){
      if (c[i] == '\n'){
        if (isNumeric(cell.getStringCellValue())){
          cell.setCellValue(Double.valueOf(cell.getStringCellValue()).doubleValue());
        }
        
        rowCnt++;
        row = sheet.createRow(rowCnt);
        colCnt = 0;
        cell = row.createCell(colCnt);
      }
      else if (c[i] == (char)9){
        if (isNumeric(cell.getStringCellValue())){
          cell.setCellValue(Double.valueOf(cell.getStringCellValue()).doubleValue());
        }
        
        colCnt++;
        cell = row.createCell(colCnt);
      }
      else{
        cell.setCellValue(cell.getStringCellValue() + c[i]);
      }
    }
    
   
    return workbook;
}

Open in new window

This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
sciuriware

:)