EXCEL

/**
 *
 */
package Delete_Null_Line;

import java.io.File;
import java.io.IOException;
import java.util.*;

import javax.swing.JFileChooser;

import jxl.*;
import jxl.read.biff.BiffException;
import jxl.write.*;
//import jxl.write.Boolean;
import jxl.write.biff.RowsExceededException;
import  common_function.CommonFunction;
/**
 *
 *
 */
public class DeleteNullLine {


 

 /**
  * <p>
  * Title: 该方法作用是删除空行
  * </p>
  * <p>
  * </p>
  * <p>
  * Copyright: Copyright (c) 2003
  * </p>
  * <p>
  * Filename: myExcel.java
  * </p>
  *
  *
  * @version 1.0
  */

     private Workbook workbook;

     private Sheet sheet;

     public static void main(String[] arges)
     {
         int countFlag = 0;

      //   String fileName = "E://MSG9000.xls";
         String []fileNames = null;
         fileNames = CommonFunction.selectPath("C://Documents and Settings//sd//桌面");//C://Documents and Settings//sd//桌面
         String fileName  = fileNames[0];
 //        String fileNameB = "E://MSG9000_B.xls";
         String fileNameB = fileName.substring(0,fileName.lastIndexOf("//")+1)+"END"+fileName.substring(fileName.lastIndexOf("//")+1,fileName.length());
         String fileNameBB = "E://MSGA000_BB.xls";
         String fileNameC = "E://MSGA000_C.xls";
//         String fileName = "E://SSA.xls";
//         String fileNameB = "E://SSA_B.xls";
//         String fileNameBB = "E://SSA_BB.xls";
//         String fileNameC = "E://SS_C.xls";
         // begin 先将待操作文件复制一份
         Workbook workBook_Source = null;
         Workbook workBook_SourceB = null;
         WritableWorkbook writeWorkBook_Middle = null;
         WritableWorkbook writeWorkBook_END = null;
        try
        {
           
             try
             {
                 workBook_Source = Workbook.getWorkbook(new File(fileName));
             }
             catch(BiffException e1)
             {
                 // TODO 自动生成 catch 块
                 e1.printStackTrace();
             }
             writeWorkBook_Middle = Workbook.createWorkbook(new File(fileNameB));
      //       writeWorkBook_Middle.createSheet("msgA", 0);
        //     writeWorkBook_Middle.createSheet("msgA", 0);
             writeWorkBook_Middle.createSheet("sbc", 0);//-------------------------------------------------------------------

        
            
           //  Sheet workBook_Source_Sheet = workBook_Source.getSheet(0);
             //读取 SS 的也是0,因为excel文件只有一个SS sheet-----------------------------------------------------------
             Sheet workBook_Source_Sheet = workBook_Source.getSheet(0);
               int rowNumbers = workBook_Source_Sheet.getRows();
               int columnNumbers = workBook_Source_Sheet.getColumns();
                  Cell []cell = new Cell[columnNumbers];
                  String []value = new String[columnNumbers];
                  Label []label = new Label[columnNumbers];
                  int globalj=0;
               for (int i = 0,realrow=0 ; i < rowNumbers;i++ )
               {
                 
                      
                     for(int j = 0; j < 4; j++)
                     { 
                      if(workBook_Source_Sheet.getCell(j, i)!=null)
                      {
                       cell[j] = workBook_Source_Sheet.getCell(j, i);
                      }
                      
                          //获取的值都经过过滤前后空格符的内容
                          if(cell[j]!=null)
                          {
                          value[j] = cell[j].getContents().trim();

                          }
                          label[j] = new Label(j,realrow,value[j]);

                     }
                                  
                         if(!(value[0].equals("") &&value[1].equals("")&&value[2].equals("")&&value[3].equals(""))) //&& !value.trim().equals("")) value[0].equals("") &&  && value[3].length()>4
                         { 
//                           System.out.println(i);
//                           System.out.println(3);
//                           System.out.println(value[2]);
//                          String value_space = "";                                                  
//                          Label label1 = new Label(1, i, value[2]);
//                          
//                          //第3列的值覆盖第2列,第3列的值置空
//                       
//                             writeWorkBook_Middle.getSheet(0).addCell(label1);
//                             Label label2 = new Label(2, i, value_space);
//                             writeWorkBook_Middle.getSheet(0).addCell(label2);
//                           
//                        
//                         }
//                         else
//                         {
                          for(int j =0 ;j< 4;j++)
                          {
                           writeWorkBook_Middle.getSheet(0).addCell(label[j]);
                          }
                          System.out.println(realrow);
                          realrow= realrow+1;
                         }
              
               
               }
               writeWorkBook_Middle.write();
               writeWorkBook_Middle.close();
               workBook_Source.close();
            //   String tipName = fileNameB.substring(fileNameB.lastIndexOf("//"+1,fileNameB.length()));
               System.out.println("---------------------------------ok");
      
              

            }
           catch(Exception e)
           {
               e.printStackTrace();
           }
           workBook_Source.close();

     }

 

 

 

}

你可能感兴趣的:(EXCEL)