开发者

cannot able to encode the excel sheet using jexceapi

I have to create one excel 开发者_Go百科sheet using JExcel api..I cannt able to encode the excel file and am not able to sure whether the file is encoded or not ?... pls help

import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Locale;

import jxl.Sheet;
import jxl.SheetSettings;
import jxl.Workbook;
import jxl.WorkbookSettings;
import jxl.read.biff.BiffException;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;
import jxl.write.WriteException;

public class Jexcel_test {

public static void main(String[] args) {
    // TODO Auto-generated method stub

    try
    {       

        WorkbookSettings ws = new WorkbookSettings();
        ws.setLocale(new Locale("en", "EN"));        
        ws.setCharacterSet(0);
        ws.setEncoding("utf-8");
        ws.setDrawingsDisabled(true);
        ws.setGCDisabled(true);

        System.out.println(ws.getCharacterSet());
        System.out.println(ws.getArrayGrowSize());
        System.out.println(ws.getExcelDisplayLanguage());
        System.out.println(ws.getExcelRegionalSettings());


        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        System.out.println("Enter filename  :");
        File filename= new File("f:/"+br.readLine()+".xls"); 

        Workbook wb1=Workbook.getWorkbook(filename, ws);

        Sheet s  = wb1.getSheet(0);

       SheetSettings settings = s.getSettings();
        settings.setDefaultRowHeight(500);
        if(!settings.isProtected())
        {               
            settings.setPassword("test");               
        }   
        settings.setFitToPages(true);   

        System.out.println(s.getName());


        for (int row = 1; row < s.getRows(); row++) {
            String val = s.getCell(0, row).getContents().trim();
            System.out.println(val);
        }


        wb1.close();


        System.out.println("Enter new filename  :");
        File filename1= new File("f:/"+br.readLine()+".xls"); 
        WritableWorkbook wb2 = Workbook.createWorkbook(filename1, ws);
        WritableSheet sheet = wb2.createSheet("mysheet",0); 

        SheetSettings settings1 = sheet.getSettings();
        settings1.setDefaultRowHeight(500);
        settings1.setProtected(true);
        settings1.setPassword("test");
        settings1.setFitToPages(true);  
        System.out.println("Workbook  "+filename1+"  created");

        wb2.write();
        wb2.close();

    }
    catch (IOException e)
    {
      e.printStackTrace();
    }

    catch (BiffException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    catch (WriteException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

}

}


First write some non-ascii data in one of the column and then read the same.. you'll get the answer.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜