简体   繁体   中英

Label not being recognized even though jxl import and API are there

I am trying to teach myself how to write to an excel file and just copy and pasted some code from a tutorial, and this code should work without errors as I have seen similar on several other tutorials. So why is Label (error is: constructor is undefined) and AddCell (error is: The method addCell(WritableCell) in the type WritableSheet is not applicable for the arguments (Label)) acting up on me?

 private void addCaption(WritableSheet sheet, int column, int row, String s)
      throws RowsExceededException, WriteException {
    Label label;
    label = new Label(column, row, s, timesBoldUnderline);  //error
    sheet.addCell(label); //error
  }

Imports:

import java.awt.Label;
import java.io.File;
import java.io.IOException;
import java.util.Locale;

import jxl.JXLException;
import jxl.CellView;
import jxl.Workbook;
import jxl.WorkbookSettings;
import jxl.format.UnderlineStyle;
import jxl.write.Formula;
import jxl.write.Label;
import jxl.write.Number;
import jxl.write.WritableCell;
import jxl.write.WritableCellFormat;
import jxl.write.WritableFont;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;
import jxl.write.WriteException;
import jxl.write.biff.RowsExceededException;

In your imports you import two different Labels. One from java.awt and one from jxl.write . You get the error that the constructor is not defined so your code is most likely using the wrong Label wich does not have a constructor like that. And you also get the error that the addCell() method is not applicable for the arguments Label so again the code probably uses the wrong Label.

All of this can be easily fixed by adding the package to the Label like this:

jxl.write.Label label;
label = new jxl.write.Label(column, row, s, timesBoldUnderline);
sheet.addCell(label);

That should fix your problem.

Good luck :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM