-
package com.gxt.testcase.service.impl;


import com.jj.system.pojo.web.SmUploadfile;
import com.jj.system.service.web.SmUploadfileService;
import java.io.InputStream;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import java.io.FileInputStream;
import org.apache.poi.hwpf.HWPFDocument;
import org.apache.poi.hwpf.usermodel.TableIterator;
import org.apache.poi.hwpf.usermodel.Table;
import org.apache.poi.hwpf.usermodel.TableRow;
import org.apache.poi.hwpf.usermodel.TableCell;
import org.apache.poi.hwpf.usermodel.Range;
import java.io.IOException;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hwpf.extractor.WordExtractor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class ExecuteDataTimer
{

  @Autowired
  private SmUploadfileService smUploadfileService;
  
  
  /**
   * 解析excel中的内容
   * @param smUploadfile
   * @return
   * @throws IOException
   */
  private Map<String, Object> testdataImport(SmUploadfile smUploadfile)
    throws IOException
  {

	  //1.根据路径取到相关文件
      String filePath = this.smUploadfileService.getAbsFilePath(smUploadfile.getPath() + smUploadfile.getId());

      InputStream is = new FileInputStream(filePath);

      HSSFWorkbook hssfWorkbook = new HSSFWorkbook(is);

      //2.循环工作簿进行解析取值
      for (int numSheet = 0; numSheet < hssfWorkbook.getNumberOfSheets(); numSheet++)
      {
        TpTestdataVO tpTestdataVO = new TpTestdataVO();

        tpTestdataVO.setFileId(smUploadfile.getId());

        HSSFSheet hssfSheet = hssfWorkbook.getSheetAt(numSheet);

        System.out.println("===========" + hssfSheet.getSheetName());

        //3.判断工作面是否为空,如果不为空,则进行解析操作
        if (hssfSheet != null)
        {
          //4.获取第0行的内容
          HSSFRow hssfRow0 = hssfSheet.getRow(0);
		  //5.获取第0行第1列的内容
		  hssfRow0.getCell(0)
        }
	  }
  }

  /**
   * 解析word文件内容-马康-2016年12月14日10:38:38
   * @param smUploadfile 传入的文件内容
   * @return
   */
  private Map<String, Object> testWordImport(SmUploadfile smUploadfile)
  {

      //1.通过路径获取文件
      String filePath = this.smUploadfileService.getAbsFilePath(smUploadfile.getPath() + smUploadfile.getId());
      //2.通过路径获取字节流
      FileInputStream in = new FileInputStream(filePath);
      POIFSFileSystem pfs = new POIFSFileSystem(in);
      HWPFDocument hwpf = new HWPFDocument(pfs);
      
	  //3.获取字节流的组个数
      Range range = hwpf.getRange();
     
      TableIterator it = new TableIterator(range);
      //4.循环模板表
      while (it.hasNext())
      {
        System.out.println("table===============");
        //5.获得world中的下一个表格信息
        Table tb = it.next();

        //6.获得第一行的内容
        TableRow tr0 = tb.getRow(0);
		//7.获取行数
        int asdfaf =tb.numRows();
		//8.获取列内容
		TableCell td = tr0.getCell(1);
        String content = getCellText(td.text().replace(" ", ""));
	  }
	  
       
  }
  
    private String getCellText(String text)
	{
		return text.replace("\007", "");
	}

}
-