object ExportColor {
def ExportImportFile(lang:String,titleList: List[String], contextList: List[List[String]]): String = { //导出添加颜色
var fileName = "fail"
log.info("##########start file export")
try {
var title = "aaa"
//生成文件
val exportFile = new File(s"$LocalFilePath/${title}_${formatTimStamp()}.xlsx")
if (!exportFile.getParentFile.exists())
exportFile.getParentFile.mkdirs
if (!exportFile.exists())
exportFile.createNewFile
//工作区
val wb: XSSFWorkbook = new XSSFWorkbook()
//创建第一个sheet
val sheet: XSSFSheet = wb.createSheet(title)
//生成第一行
var row: XSSFRow = sheet.createRow(0)
//给Excel添加背景颜色
val cellStyle: XSSFCellStyle = wb.createCellStyle()
cellStyle.setFillForegroundColor(IndexedColors.RED.getIndex())
cellStyle.setFillPattern(CellStyle.SOLID_FOREGROUND)
// headList.map(subtitle=>subtitle.map(subtitle=>row.createCell(subtitle).setCellValue(subtitle)))
//生成表头
for (k <- 0 until titleList.length) {
row.createCell(k).setCellValue(titleList(k))
}
var index = 1 //行
//开始写数据
contextList.map {
recordRow =>
row = sheet.createRow(index)
var i: Int = 0
recordRow.map {
fileColumn =>
row.createCell(i).setCellValue(fileColumn)
i = i + 1
}
index = index + 1
//给错误的单元格添加颜色
val columnLast = recordRow(recordRow.length - 1)
if(columnLast.length>=1 && columnLast != null && columnLast != ""){
val cellIndex = columnLast.split(",").toList
cellIndex.map {
indexCell =>
val cell = row.getCell(indexCell.toInt)
cell.setCellStyle(cellStyle)
}
}
}
}
def ExportImportFile(lang:String,titleList: List[String], contextList: List[List[String]]): String = { //导出添加颜色
var fileName = "fail"
log.info("##########start file export")
try {
var title = "aaa"
//生成文件
val exportFile = new File(s"$LocalFilePath/${title}_${formatTimStamp()}.xlsx")
if (!exportFile.getParentFile.exists())
exportFile.getParentFile.mkdirs
if (!exportFile.exists())
exportFile.createNewFile
//工作区
val wb: XSSFWorkbook = new XSSFWorkbook()
//创建第一个sheet
val sheet: XSSFSheet = wb.createSheet(title)
//生成第一行
var row: XSSFRow = sheet.createRow(0)
//给Excel添加背景颜色
val cellStyle: XSSFCellStyle = wb.createCellStyle()
cellStyle.setFillForegroundColor(IndexedColors.RED.getIndex())
cellStyle.setFillPattern(CellStyle.SOLID_FOREGROUND)
// headList.map(subtitle=>subtitle.map(subtitle=>row.createCell(subtitle).setCellValue(subtitle)))
//生成表头
for (k <- 0 until titleList.length) {
row.createCell(k).setCellValue(titleList(k))
}
var index = 1 //行
//开始写数据
contextList.map {
recordRow =>
row = sheet.createRow(index)
var i: Int = 0
recordRow.map {
fileColumn =>
row.createCell(i).setCellValue(fileColumn)
i = i + 1
}
index = index + 1
//给错误的单元格添加颜色
val columnLast = recordRow(recordRow.length - 1)
if(columnLast.length>=1 && columnLast != null && columnLast != ""){
val cellIndex = columnLast.split(",").toList
cellIndex.map {
indexCell =>
val cell = row.getCell(indexCell.toInt)
cell.setCellStyle(cellStyle)
}
}
}
}