java动态生成带下拉框的Excel导入模版实现了,但是把excel表格写上内容关闭之后,再次打开时,存在以下问题:
显示数据库里内容的下拉框没有了;
但是类似String[] str1 = {"男","女","未知"};这样死的数据的下拉框倒是还有。
问题是兼容性问题
下面是图片
代码是根据链接写的:https://www.cnblogs.com/mingyue1818/p/6054188.html
可以试试Free Spire.XLS for Java
import com.spire.xls.*;
public class listDataValidation {
public static void main(String[] args) {
Workbook workbook = new Workbook();
workbook.loadFromFile("data/DataValidation.xlsx");
Worksheet sheet = workbook.getWorksheets().get(0);
sheet.getCellRange("A7").setText("Beijing");
sheet.getCellRange("A8").setText("New York");
sheet.getCellRange("A9").setText("Denver");
sheet.getCellRange("A10").setText("Paris");
CellRange range = sheet.getCellRange("D10");
range.getDataValidation().setShowError(true);
range.getDataValidation().setAlertStyle(AlertStyleType.Stop);
range.getDataValidation().setErrorTitle("Error");
range.getDataValidation().setErrorMessage("Please select a city from the list");
//设置下拉列表的单元格区域
range.getDataValidation().setDataRange(sheet.getCellRange("A7:A10"));
String output = "output/ListDataValidation_out.xlsx";
workbook.saveToFile(output, ExcelVersion.Version2013);
}
}
谢谢