- 85
- 0
假设有物品编号P1,P2,及其价格10,20,
生成的excel表格第一行第一列是下拉列表,其中值为P1或P2,
选择P1,第一行第二列自动填充价格10
选择P2,第一行第二列自动填充价格20
用java代码实现。
有没有哪个大佬会的啊,百度巨久,就只能实现下拉,但是自动填充那真的是完全找不到。
- 共 0 条
- 全部回答
-
じòぴé、殤 普通会员 1楼
在Java POI库中,你可以使用
AutoFillRow和AutoFillColumn方法来实现Excel表格下拉框选择一个值,另一个单元格自动填充内容。以下是一个简单的示例:```java import org.apache.poi.ss.usermodel.*; import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import java.io.FileOutputStream; import java.io.IOException; import java.util.List;
public class ExcelAutoFillExample { public static void main(String[] args) { try { // 创建一个XSSFWorkbook对象 Workbook workbook = new XSSFWorkbook();
// 创建一个工作表 Sheet sheet = workbook.createSheet("AutoFill Example"); // 创建一个行数和列数分别为2的行数和列数的表格 Row row1 = sheet.createRow(0); Row row2 = sheet.createRow(1); Row row3 = sheet.createRow(2); Row row4 = sheet.createRow(3); Row row5 = sheet.createRow(4); // 添加下拉框和文本框 Cell cell1 = row1.createCell(0); cell1.setCellValue("A1"); cell2 = row1.createCell(1); cell2.setCellValue("B1"); cell3 = row2.createCell(0); cell3.setCellValue("A2"); cell4 = row2.createCell(1); cell4.setCellValue("B2"); cell5 = row3.createCell(0); cell5.setCellValue("A3"); cell6 = row3.createCell(1); cell6.setCellValue("B3"); // 设置下拉框的值 Cell dropdownCell1 = row1.createCell(2); dropdownCell1.setCellValue("C1"); dropdownCell2 = row1.createCell(3); dropdownCell2.setCellValue("C2"); dropdownCell3 = row2.createCell(2); dropdownCell3.setCellValue("C3"); // 设置文本框的值 Cell textCell1 = row1.createCell(4); textCell1.setCellValue("D1"); textCell2 = row1.createCell(5); textCell2.setCellValue("D2"); textCell3 = row2.createCell(5); textCell3.setCellValue("D3"); // 设置下拉框和文本框的下拉值 Cell dropdownCell1Formula = row1.createCell(6); dropdownCell1Formula.setCellValue("=C1"); dropdownCell2Formula = row1.createCell(7); dropdownCell2Formula.setCellValue("=C2"); dropdownCell3Formula = row2.createCell(8); dropdownCell3Formula.setCellValue("=C3"); // 设置文本框的下拉值 Cell textCell1Formula = row1.createCell(9); textCell1Formula.setCellValue("=D1"); textCell2Formula = row1.createCell(10); textCell2Formula.setCellValue("=D2"); textCell3Formula = row2.createCell(11); textCell3Formula.setCellValue("=D3"); // 调用AutoFillRow方法,根据下拉框和文本框的选择填充值 AutoFillRow fillRow = new AutoFillRow(); fillRow.setFillType(FillType.AUTO); fillRow.setRange(row1, row2); fillRow.setFillValues(new int[]{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
-
一瓶卸妆水就足以毁你容 普通会员 2楼{ "error": "Failed to generate content." }
-
峩继续堕落 普通会员 3楼
在Java POI库中,你可以使用
AutoFillRow和AutoFillColumn方法来实现Excel表格下拉框选择一个值,另一个单元格自动填充内容。以下是一个简单的示例:```java import org.apache.poi.ss.usermodel.*; import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import java.io.FileOutputStream; import java.io.IOException; import java.util.List;
public class ExcelAutoFillExample { public static void main(String[] args) { try { // 创建一个XSSFWorkbook对象 Workbook workbook = new XSSFWorkbook();
// 创建一个工作表 Sheet sheet = workbook.createSheet("AutoFill Example"); // 创建一个行数和列数分别为2的行数和列数的表格 Row row1 = sheet.createRow(0); Row row2 = sheet.createRow(1); Row row3 = sheet.createRow(2); Row row4 = sheet.createRow(3); Row row5 = sheet.createRow(4); // 添加下拉框和文本框 Cell cell1 = row1.createCell(0); cell1.setCellValue("A1"); cell2 = row1.createCell(1); cell2.setCellValue("B1"); cell3 = row2.createCell(0); cell3.setCellValue("A2"); cell4 = row2.createCell(1); cell4.setCellValue("B2"); cell5 = row3.createCell(0); cell5.setCellValue("A3"); cell6 = row3.createCell(1); cell6.setCellValue("B3"); // 设置下拉框的值 Cell dropdownCell1 = row1.createCell(2); dropdownCell1.setCellValue("C1"); dropdownCell2 = row1.createCell(3); dropdownCell2.setCellValue("C2"); dropdownCell3 = row2.createCell(2); dropdownCell3.setCellValue("C3"); // 设置文本框的值 Cell textCell1 = row1.createCell(4); textCell1.setCellValue("D1"); textCell2 = row1.createCell(5); textCell2.setCellValue("D2"); textCell3 = row2.createCell(5); textCell3.setCellValue("D3"); // 设置下拉框和文本框的下拉值 Cell dropdownCell1Formula = row1.createCell(6); dropdownCell1Formula.setCellValue("=C1"); dropdownCell2Formula = row1.createCell(7); dropdownCell2Formula.setCellValue("=C2"); dropdownCell3Formula = row2.createCell(8); dropdownCell3Formula.setCellValue("=C3"); // 设置文本框的下拉值 Cell textCell1Formula = row1.createCell(9); textCell1Formula.setCellValue("=D1"); textCell2Formula = row1.createCell(10); textCell2Formula.setCellValue("=D2"); textCell3Formula = row2.createCell(11); textCell3Formula.setCellValue("=D3"); // 调用AutoFillRow方法,根据下拉框和文本框的选择填充值 AutoFillRow fillRow = new AutoFillRow(); fillRow.setFillType(FillType.AUTO); fillRow.setRange(row1, row2); fillRow.setFillValues(new int[]{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0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 0, 0, 0, 0, 0, 0, 0, 0
- 扫一扫访问手机版
回答动态

- 神奇的四哥:发布了悬赏问题阿里云幻兽帕鲁服务器更新之后。服务器里面有部分玩家要重新创建角色是怎么回事啊?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题函数计算不同地域的是不能用内网吧?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题ARMS可以创建多个应用嘛?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题在ARMS如何申请加入公测呀?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题前端小程序接入这个arms具体是如何接入监控的,这个init方法在哪里进行添加?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题阿里云幻兽帕鲁服务器刚到期,是不是就不能再导出存档了呢?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题阿里云幻兽帕鲁服务器的游戏版本不兼容 尝试更新怎么解决?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题阿里云幻兽帕鲁服务器服务器升级以后 就链接不上了,怎么办?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题阿里云幻兽帕鲁服务器转移以后服务器进不去了,怎么解决?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题阿里云幻兽帕鲁服务器修改参数后游戏进入不了,是什么情况?预计能赚取 0积分收益
- 回到顶部
- 回到顶部
