简体   繁体   English

即使存在jxl导入和API,标签也无法识别

[英]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. 我正在尝试教自己如何写入excel文件,然后仅复制和粘贴教程中的一些代码,并且该代码应该可以正常工作,而我在其他几本教程中也看到过类似的情况。 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? 那么,为什么是Label(错误是:构造函数未定义)和AddCell(错误是:WritableSheet类型的addCell(WritableCell)方法不适用于实参(Label))?

 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. 在导入中,您将导入两个不同的Labels。 One from java.awt and one from jxl.write . 一个来自java.awt ,另一个来自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. 您会得到一个错误,即未定义构造函数,因此您的代码很可能使用了错误的Label,而没有这样的构造函数。 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. 而且,您还会收到错误,指出addCell()方法不适用于参数Label,因此代码再次可能使用了错误的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 :) 祝好运 :)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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