背景:
数仓项目中经常遇到业务手工发数据,然后要求补录数据的情况。每次通过excel拉取费时费力,使用小工具提高效率
语言:
scala
maven依赖:
<!-- https://mvnrepository.com/artifact/org.apache.poi/poi --> <dependency> <groupId>org.apache.poi</groupId> <artifactId>poi</artifactId> <version>4.1.0</version> </dependency>
脚本:
package Excel import java.io.{File, FileInputStream, InputStream, PrintWriter} import org.apache.poi.hssf.usermodel.HSSFWorkbook import org.apache.poi.ss.usermodel.{Cell, CellType} object TestExcel { def main(args: Array[String]): Unit = { //读取excel val file = new File(args(0)) val stream = new FileInputStream(file) //输出文件 var output=new PrintWriter("script.sql") //工作簿 val workBook = new HSSFWorkbook(stream) //获取sheets集合 val sheets = workBook.sheetIterator() //sheet递归