java jxl怎么让Excel文件的其中一行数据变成红色
如题,正在做一个Excel文件导入,错误数据需要在Excel文件中让那行错误信息变成红色。给段详细代码做分析,谢谢...
如题,正在做一个Excel文件导入,错误数据需要在Excel文件中让那行错误信息变成红色。
给段详细代码做分析,谢谢 展开
给段详细代码做分析,谢谢 展开
1个回答
展开全部
import jxl.Workbook;
import jxl.format.Colour;
import jxl.write.*;
import java.io.File;
public class Test {
public static void main(String []args)throws Exception{
WritableWorkbook workbook = Workbook.createWorkbook(new File("test.xls"));
WritableSheet sheet = workbook.createSheet("test", 0);
WritableCell cell = new Label(0,0,"test");
WritableCellFormat writableCellFormat = new WritableCellFormat();
writableCellFormat.setBackground(Colour.RED);
cell.setCellFormat(writableCellFormat);
sheet.addCell(cell);
workbook.write();
workbook.close();
}
}
import jxl.format.Colour;
import jxl.write.*;
import java.io.File;
public class Test {
public static void main(String []args)throws Exception{
WritableWorkbook workbook = Workbook.createWorkbook(new File("test.xls"));
WritableSheet sheet = workbook.createSheet("test", 0);
WritableCell cell = new Label(0,0,"test");
WritableCellFormat writableCellFormat = new WritableCellFormat();
writableCellFormat.setBackground(Colour.RED);
cell.setCellFormat(writableCellFormat);
sheet.addCell(cell);
workbook.write();
workbook.close();
}
}
追问
来点注释成么?看不太明白啊
追答
import jxl.Workbook;
import jxl.format.Colour;
import jxl.write.*;
import java.io.File;
public class Test {
public static void main(String []args)throws Exception{
//创建一个Workbook
WritableWorkbook workbook = Workbook.createWorkbook(new File("test.xls"));
//创建一个sheet
WritableSheet sheet = workbook.createSheet("test", 0);
//创建一个单元格,文本类型
WritableCell cell = new Label(0,0,"test");
//创建一个单元格样式
WritableCellFormat writableCellFormat = new WritableCellFormat();
//设置样式的背景色为红色
writableCellFormat.setBackground(Colour.RED);
//设置单元格的样式
cell.setCellFormat(writableCellFormat);
//将单元格添加到sheet中
sheet.addCell(cell);
//保存并关闭excel
workbook.write();
workbook.close();
}
}
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询