package com.connor.touliao;

import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.util.List;

import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

import com.teamcenter.rac.aif.AbstractAIFOperation;
import com.teamcenter.rac.util.MessageBox;

public class TouliaoOperation extends AbstractAIFOperation{
	
	private File outPathFile;
	
	private List<String[]> difBomline;
	public TouliaoOperation(File f, List<String[]> difBomline) {
		this.outPathFile=f;
		this.difBomline=difBomline;
	}

	@Override
	public void executeOperation() throws Exception {
		// TODO Auto-generated method stub
		InputStream itemMoudel=TouliaoOperation.class.getResourceAsStream("投料导出模板.xlsx");
		XSSFWorkbook wb2 = null;
		wb2 = new XSSFWorkbook(itemMoudel);
		int t=1;
		XSSFSheet sheetItem = wb2.getSheetAt(0);
		
		
		for(String[] message : difBomline) {
			XSSFRow row = sheetItem.getRow(t);
			if(row==null) {
				row = sheetItem.createRow(t);
			}
			
			for(int i=0;i<message.length;i++) {
				XSSFCell createCell = row.createCell(i);
				createCell.setCellType(Cell.CELL_TYPE_STRING);
				createCell.setCellValue(message[i]);
			}
			t++;
		}
		
		FileOutputStream output2 = new FileOutputStream(new File(outPathFile.getAbsoluteFile()+File.separator+"投料检查结果.xlsx"));
		wb2.write(output2);
		output2.close();
		itemMoudel.close();
		MessageBox.post("导出投料检查结果成功","提示",MessageBox.INFORMATION);
	}

	
	
}
