解析excel中的A,C列,生成指定格式(sql)
可以指定excel,sql模板,最后生成sql
![](https://img-blog.csdnimg.cn/img_convert/0dddb439dbfd6ee79ed3db701d8ca58c.png)
![](https://img-blog.csdnimg.cn/img_convert/61d444a02b5b577e8859026ad1a2f622.png)
@Test
public void excel2FormatText() {
/* 需要修改以下5项 */
//1. 列号,从0开始 修改Excel2FormatTextListener中的 invoke 方法,formatStr需要几个参数传入几个值
String excelPath = "./com-xinxian-service/src/main/resource/excel生成指定格式.xlsx";
String formatStr = "update test_table set name = '%s' where id = %s;";
String resultPath = "./com-xinxian-service/src/main/resource/excel生成指定格式结果.txt";
String sheetName = "Sheet1";
try {
FileInputStream fileInputStream = new FileInputStream(excelPath);
Excel2FormatTextListener excel2FormatTextListener = new Excel2FormatTextListener(formatStr);
EasyExcel.read(fileInputStream, excel2FormatTextListener).ignoreEmptyRow(false).sheet(sheetName).autoTrim(true).doRead();
List<String> resultList = excel2FormatTextListener.getResult();
/* 写出结果 */
if (CollectionUtils.isNotEmpty(resultList)) {
FileUtils.writeList2File(resultList, resultPath);
}
} catch (Exception e) {
e.printStackTrace();
}
}
代码地址:
另外excel快捷键分享:command+shift+上下左右键 快捷到excel边界