[英]How to replace default jtable column values when exporting rows to Excel - Java
for (int i = 0; i < model.getRowCount(); i++) {
XSSFRow newRow = sheet1.createRow(i);
for (int j = 0; j < model.getColumnCount(); j++) {
XSSFCell excelCell = newRow.createCell((short) j);
if (j == model.getColumnCount() - 1) {
JLabel excelJL = (JLabel) model.getValueAt(i, j);
ImageIcon excelImageIcon = (ImageIcon) excelJL.getIcon();
String imagePath = excelImageIcon.getDescription();
//[i][j] = imagePath;
}
excelCell.setCellValue(model.getValueAt(i, j).toString());
}
}
正在将数据从 jtable 导出到 excel,如何将imagePath字符串设置为在 excel 列中设置以替换最后一个 jtable 列。 在这种情况下,最后一列输出 jlabel 模型而不是输出图像路径。 我有一种提取图像路径的方法,我想用新数据替换该列,该数据是图像路径字符串并将其存储在“imagePath”变量中
//Loop through the jtable columns and rows to get its values
for (int i = 0; i < model.getRowCount(); i++) {
XSSFRow excelRow = excelSheet.createRow(i);
for (int j = 0; j < model.getColumnCount(); j++) {
XSSFCell excelCell = excelRow.createCell(j);
//Change the image column to output image path
//Fourth column contains images
if (j == model.getColumnCount() - 1) {
JLabel excelJL = (JLabel) model.getValueAt(i, j);
ImageIcon excelImageIcon = (ImageIcon) excelJL.getIcon();
//Image Name Is Stored In ImageIcons Description First set it And Then Retrieve it.
excelImagePath = excelImageIcon.getDescription();
}
excelCell.setCellValue(model.getValueAt(i, j).toString());
if (excelCell.getColumnIndex() == model.getColumnCount() - 1) {
excelCell.setCellValue(excelImagePath);
}
}
}
正在更改最后一列。 所以这段代码将所有列值更改为传递参数的值。 就我而言,我正在显示图像路径。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.