我哪里错了?
我正在关注本教程:https://www.youtube.com/watch ?v=PvrnbhGeSKE
但是,当我粘贴代码时,Eclipse 给出了这个错误:“ALIGN_CENTER 无法解析或不是字段”
package main;
import entities.*;
import dao.*;
import java.util.*;
import org.apache.poi.hssf.usermodel.*;
import org.apache.poi.hssf.util.*;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.ss.util.*;
public class Main {
public static void main(String[] args) {
try {
ProductModel pmodel = new ProductModel();
HSSFWorkbook workbook = new HSSFWorkbook();
HSSFSheet sheet = workbook.createSheet("List Products");
Row rowheading = sheet.createRow(0);
rowheading.createCell(0).setCellValue("Id");
rowheading.createCell(1).setCellValue("Name");
rowheading.createCell(2).setCellValue("Creation Date");
rowheading.createCell(3).setCellValue("Price");
rowheading.createCell(4).setCellValue("Quantity");
rowheading.createCell(5).setCellValue("Sub Total");
for (int i = 0; i < 6; i++) {
CellStyle stylerowHeading = workbook.createCellStyle();
Font font = workbook.createFont();
font.setBold(true);
font.setFontName(HSSFFont.FONT_ARIAL);
font.setFontHeightInPoints((short) 11);
stylerowHeading.setFont(font);
stylerowHeading.setVerticalAlignment(CellStyle.ALIGN_CENTER);
rowheading.getCell(i).setCellStyle(stylerowHeading);
}
} catch (Exception e) {
System.out.println(e.getMessage());
}
}
}
Run Code Online (Sandbox Code Playgroud)
这发生在 MainActivity 的这段代码中:
stylerowHeading.setVerticalAlignment(CellStyle.ALIGN_CENTER);
rowheading.getCell(i).setCellStyle(stylerowHeading);
Run Code Online (Sandbox Code Playgroud)
具体错误在“CellStyle.ALIGN_CENTER”
这些常量已移至单独的类中。正确的做法应该是:
stylerowHeading.setVerticalAlignment(VerticalAlignment.CENTER);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
9088 次 |
| 最近记录: |