idea本机能运行正常但是打包成exe以后就出错
求大神们解解惑谢谢
package com.xy.controller;
import com.microsoft.schemas.office.visio.x2012.main.impl.CellTypeImpl;
import com.xy.controller.actionlistenerimpl.transiferActionListener;
import com.xy.model.Factory;
import com.xy.model.model;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellType;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Locale;
import java.util.UUID;
import static java.sql.JDBCType.DATE;
import static java.sql.JDBCType.NUMERIC;
public class importExcel {
private HSSFCell cell,cell0;
private File file;
public importExcel(File file){
try {
this.file=file;
this.importExcelCsv(file);
} catch (Exception e) {
e.printStackTrace();
}
}
public File getFile() {
return file;
}
public void setFile(File file) {
this.file = file;
}
//1、将导高复制到模板第6、7列
public void importExcelCsv(File file) throws Exception {
ExcelOutput excelOutput = new ExcelOutput();
//导高列
ArrayList<HSSFCell> GuideGeightarr = excelOutput.InputExcel(5,file);
//拉出值列
ArrayList<HSSFCell> StaggerValuearr = excelOutput.InputExcel(4,file);
//速度列
ArrayList<HSSFCell> Quickarr = excelOutput.InputExcel(11,file);
//速度列
ArrayList<HSSFCell> Kmarr = excelOutput.InputExcel(9,file);
//定位类型列
ArrayList<HSSFCell> Positionarr = excelOutput.InputExcel(7,file);
FileInputStream fileInputStream = new FileInputStream(file);
POIFSFileSystem fs=new POIFSFileSystem(fileInputStream);
// 拿到file中excel对象
HSSFWorkbook workbook = new HSSFWorkbook(fs);
HSSFSheet sheet1 = workbook.createSheet("sheet"+UUID.randomUUID());
int size = GuideGeightarr.size();
//遍历单元格并写入Array数组中的数据
for(int i=1;i<size;i++){
Object o = GuideGeightarr.get(i);
// System.out.println(o);
HSSFRow row = sheet1.createRow(i);
//写入第6、7列
for (int j=1;j<14;j++){
//导高列导入
if(j==6^j==7){
this.cell = row.createCell(j);
this.cell.setCellValue(new Integer(new model(GuideGeightarr.get(i)).toString()));
this.cell.setCellType(CellType.NUMERIC);
//判断类型并添加
// switch (cellType){
// case NUMERIC:
// cell.setCellType(CellType.NUMERIC);
// cell.setCellValue(GuideGeightarr.get(i).getNumericCellValue());
// break;
// case STRING:
// cell.setCellType(CellType.STRING);
// cell.setCellValue(new model( GuideGeightarr.get(i)).toString());
// break;
// case FORMULA:
// cell.setCellType(CellType.FORMULA);
// SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
// String format = simpleDateFormat.format(GuideGeightarr.get(i).getDateCellValue());
// cell.setCellValue(format);
// break;
// case BOOLEAN:
// cell.setCellType(CellType.BOOLEAN);
// cell.setCellValue(GuideGeightarr.get(i).getBooleanCellValue());
// break;
// default:break;
// }
}
//0列导入
if(j==4^j==5^j==10^j==11){
this.cell = row.createCell(j);
this.cell.setCellValue(0);
}
//拉出值列导入
if(j==8^j==9){
this.cell = row.createCell(j);
this.cell.setCellValue(new Integer(new model(StaggerValuearr.get(i)).toString()));
}
//速度列导入
if(j==2){
this.cell = row.createCell(j);
this.cell.setCellValue(new Integer(new model(Quickarr.get(i)).toString()));
this.cell.setCellType(CellType.NUMERIC);
}
//公里标列导入
if(j==1){
this.cell = row.createCell(j);
cell0 = row.createCell(j-1);
this.cell.setCellValue(new Double(new model(Kmarr.get(i)).toString()));
this.cell.setCellType(CellType.NUMERIC);
cell0.setCellValue(i);
}
//定位列导入
if(j==3){
this.cell = row.createCell(j);
if(new model(Positionarr.get(i)).toString().equals("单支定位")^new model(Positionarr.get(i)).toString().equals("双支定位")){
this.cell.setCellValue(1000);
}
if (new model(Positionarr.get(i)).toString().equals("吊弦")^Positionarr.get(i)==null){
this.cell.setCellValue(0);
}
}
}
}
HSSFRow row1 = sheet1.createRow(0);
String[] str={"序号","公里标(km)","速度(km/h)","支柱标记","弓网接触力(N)","网压","接触线高度1(mm)","接触线高度2(mm)","接触线拉出值1(mm)","接触线拉出值2(mm)","火花时间(ms)","单元分界"};
for(int i=0;i<=11;i++){
HSSFCell cell1 = row1.createCell(i);
cell1.setCellType(CellType.STRING);
cell1.setCellValue(str[i].toString());
}
//输出流
FileOutputStream outputStream=new FileOutputStream(file);
//关流
workbook.write(outputStream);
outputStream.close();
fs.close();
fileInputStream.close();
}}
package com.xy.controller;
import com.xy.view.Views;
import org.apache.poi.hssf.usermodel.*;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import java.io.File;
import java.io.FileInputStream;
import java.util.ArrayList;
public class ExcelOutput {
//文本
public int column;
private File file;
//将输出的列放到表2
public ArrayList<HSSFCell> InputExcel(int column,File file) throws Exception {
//创建数组
ArrayList<HSSFCell> columnValuearr = new ArrayList<>();
if(file.exists()){
// 输入流并解析
FileInputStream fileInputStream = new FileInputStream(file);
//文件解析器
POIFSFileSystem fs=new POIFSFileSystem(fileInputStream);
// 拿到file中excel对象
HSSFWorkbook workbook = new HSSFWorkbook(fs);
if(workbook==null){
System.exit(0);
}
//工作簿对象
HSSFSheet sheets1 = workbook.getSheet("sheets1");
//sheets1工作簿的第一个有效行
int firstRowNum = sheets1.getFirstRowNum();
//sheets1工作簿的第lastRowNum个有效行
int lastRowNum = sheets1.getLastRowNum();
//获取全部有效数据行的cell值 循环遍历 for循环的嵌套
for(int i=firstRowNum;i<lastRowNum-firstRowNum;i++){
HSSFRow row = sheets1.getRow(i);
short firstCellNum = row.getFirstCellNum();
short lastCellNum = row.getLastCellNum();
for(int j=firstCellNum;j<lastCellNum-firstCellNum;j++){
//获取第column列数据
if(j==column){
HSSFCell cell = row.getCell(j);
columnValuearr.add(cell);
}
}
}
return columnValuearr;
}
else {
System.exit(0);
return new ArrayList<>();
}
//操作表格方法
/*
public Workbook getWorkbook(String path) throws IOException {
//文件输入流
//判断文件类型若
boolean is2003Excel=getFileBoolean(path);
if (is2003Excel){
workbook = new HSSFWorkbook(inputStream);
}else {
workbook = new XSSFWorkbook(inputStream);
}
return null;
*/
}}
package com.xy.view;
import com.xy.controller.ExcelOutput;
import com.xy.controller.controller;
import com.xy.controller.importExcel;
import com.xy.model.Factory;
import com.xy.model.Paths;
import com.xy.model.model;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
public class Views {
public Views(){
Paths paths=new Paths("");
JLabel jLabel = new JLabel();
// 工厂
Factory factory = new Factory();
//主界面
JFrame jf = factory.getJFrame("文件转换器");
jf.setVisible(true);
jf.setBounds(200,200,500,500);
jf.setDefaultCloseOperation(3);
//容器
Container con = jf.getContentPane();
//跟随布局
con.setLayout(null);
//获取按钮
controller controller = new controller();
JButton jButtontransf = controller.getJButtontransf();
JButton jButtonScan = new JButton("选择文件并转换");
jButtonScan.setBounds(320,200,130,30);
jLabel.setBounds(100,200,300,70);
jLabel.setBackground(new Color(0xf0,0xf0,0x1f));
jButtonScan.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
JFileChooser jfc = new JFileChooser();
jfc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
jfc.showDialog(new JLabel(), "选择");
File selectedFile = jfc.getSelectedFile();
if(selectedFile==null){
jLabel.setText("未选择文件");
}
else{ String absolutePath = selectedFile.getAbsolutePath();
jLabel.setText(absolutePath);
paths.setPath(absolutePath);
if(selectedFile.exists()){
new importExcel(selectedFile);
}
else {System.exit(0);}}
}
});
//获取文本域
con.add(jLabel);
//添加组件
con.add(jButtonScan);
con.add(jLabel);
con.setBackground(new Color(0xff,0xff,0xff));
con.setVisible(true);
con.setBounds(0,0,500,500);
}
}
Exception in thread "AWT-EventQueue-0" java.lang.ExceptionInInitializerError
at org.apache.poi.util.HexRead.readFromString(HexRead.java:138)
at org.apache.poi.hssf.record.HyperlinkRecord.<clinit>(HyperlinkRecord.java:215)
at java.base/jdk.internal.misc.Unsafe.ensureClassInitialized0(Native Method)
at java.base/jdk.internal.misc.Unsafe.ensureClassInitialized(Unsafe.java:1155)
at java.base/jdk.internal.reflect.UnsafeFieldAccessorFactory.newFieldAccessor(UnsafeFieldAccessorFactory.java:42)
at java.base/jdk.internal.reflect.ReflectionFactory.newFieldAccessor(ReflectionFactory.java:185)
at java.base/java.lang.reflect.Field.acquireFieldAccessor(Field.java:1132)
at java.base/java.lang.reflect.Field.getFieldAccessor(Field.java:1113)
at java.base/java.lang.reflect.Field.getShort(Field.java:565)
at org.apache.poi.hssf.record.RecordFactory.recordsToMap(RecordFactory.java:444)
at org.apache.poi.hssf.record.RecordFactory.<clinit>(RecordFactory.java:292)
at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:356)
at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:319)
at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:266)
at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:236)
at com.xy.controller.ExcelOutput.InputExcel(ExcelOutput.java:27)
at com.xy.controller.importExcel.importExcelCsv(importExcel.java:51)
at com.xy.controller.importExcel.<init>(importExcel.java:34)
at com.xy.view.Views$1.actionPerformed(Views.java:62)
at java.desktop/javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1972)
at java.desktop/javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2313)
at java.desktop/javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:405)
at java.desktop/javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:262)
at java.desktop/javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:279)
at java.desktop/java.awt.Component.processMouseEvent(Component.java:6626)
at java.desktop/javax.swing.JComponent.processMouseEvent(JComponent.java:3389)
at java.desktop/java.awt.Component.processEvent(Component.java:6391)
at java.desktop/java.awt.Container.processEvent(Container.java:2266)
at java.desktop/java.awt.Component.dispatchEventImpl(Component.java:5001)
at java.desktop/java.awt.Container.dispatchEventImpl(Container.java:2324)
at java.desktop/java.awt.Component.dispatchEvent(Component.java:4833)
at java.desktop/java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4948)
at java.desktop/java.awt.LightweightDispatcher.processMouseEvent(Container.java:4575)
at java.desktop/java.awt.LightweightDispatcher.dispatchEvent(Container.java:4516)
at java.desktop/java.awt.Container.dispatchEventImpl(Container.java:2310)
at java.desktop/java.awt.Window.dispatchEventImpl(Window.java:2780)
at java.desktop/java.awt.Component.dispatchEvent(Component.java:4833)
at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:773)
at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:722)
at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:716)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:399)
at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:86)
at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:97)
at java.desktop/java.awt.EventQueue$5.run(EventQueue.java:746)
at java.desktop/java.awt.EventQueue$5.run(EventQueue.java:744)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:399)
at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:86)
at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:743)
at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:203)
at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124)
at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:113)
at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:109)
at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:90)
Caused by: java.nio.charset.UnsupportedCharsetException: Big5
at java.base/java.nio.charset.Charset.forName(Charset.java:528)
at org.apache.poi.util.StringUtil.<clinit>(StringUtil.java:37)
... 54 more