gpt4 book ai didi

java - ALIGN_CENTER 无法解析或不是字段

转载 作者:行者123 更新时间:2023-12-01 17:53:07 25 4
gpt4 key购买 nike

我哪里错了?

我正在关注本教程: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());
}
}
}

这发生在 MainActivity 的这段代码中:

stylerowHeading.setVerticalAlignment(CellStyle.ALIGN_CENTER);
rowheading.getCell(i).setCellStyle(stylerowHeading);

具体错误在“CellStyle.ALIGN_CENTER”

最佳答案

这些常量已移至单独的类中。正确的做法应该是:

stylerowHeading.setVerticalAlignment(VerticalAlignment.CENTER);

关于java - ALIGN_CENTER 无法解析或不是字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47769583/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com