HSSFCell 有个setEncoding()方法,不知道有用否?

解决方案 »

  1.   

    处理cell是可以的
        cell.setEncoding((short)1);
        cell.setCellValue("中文测试");但处理sheet和workbook确没有找到相应的encoding的方法
      

  2.   

    short rownum;
          FileOutputStream out=new FileOutputStream("c:\\testjava\\test.xls");
          HSSFWorkbook hwb=new HSSFWorkbook();//创建一个excel
          HSSFSheet s=hwb.createSheet();//新建一页
          HSSFSheet s1=hwb.createSheet();//新建第二页
          HSSFRow r=null;//声明Row行
          HSSFCell c=null;//声明Cell列
          HSSFFont fonts=hwb.createFont();
          fonts.setColor(HSSFFont.COLOR_RED);
          HSSFCellStyle cs=hwb.createCellStyle();//声明风格
          cs.setDataFormat(HSSFDataFormat.getBuiltinFormat("d-mmm-yy"));
          cs.setBorderBottom(HSSFCellStyle.BORDER_THICK);
          cs.setBottomBorderColor(org.apache.poi.hssf.util.HSSFColor.BLUE.index);
          cs.setFont(fonts);
          r=s.createRow(0);
          c=r.createCell((short)0);
          c.setCellStyle(cs);
          s.setColumnWidth((short)1,(short)3600);
          c.setCellValue(new Date());
          c=r.createCell((short)1);
          c.setEncoding(HSSFCell.ENCODING_UTF_16);
          c.setCellValue("测试测试测试测试测试测试测试测试");
          r.createCell((short)2).setCellValue(new Date());
          r.createCell((short)3).setCellValue(true);      String tt="你好";
          hwb.setSheetName(0,"第一页",HSSFWorkbook.ENCODING_UTF_16);
          hwb.setSheetName(1,"第二页",HSSFWorkbook.ENCODING_UTF_16);
          hwb.write(out);
          out.close();
      

  3.   

    public static String UnicodeToChinese(String s){
      try{
         if(s==null||s.equals("")) return "";
         String newstring=null;
         newstring=new String(s.getBytes("ISO8859_1"),"gb2312");
         return newstring;
        }
      catch(UnsupportedEncodingException e)
      {
      return s;
      }
      }public static String ChineseToUnicode(String s){
      try{
      if(s==null||s.equals("")) return "";
      String newstring=null;
      newstring=new String(s.getBytes("gb2312"),"ISO8859_1");
       return newstring;
      }
      catch(UnsupportedEncodingException e)
      {
      return s;
     }
      }
    用上面的转换一下吧,侃侃可以吗
      

  4.   

    http://www.csdn.net/expert/topic/1065/1065682.xml?temp=.4279901到这里看看,这里有总结的java中文解决办法。
      

  5.   

    我说就是啊,我看到他网站上的说明也有hwb.setSheetName(0,  "第一页  ",HSSFWorkbook.ENCODING_UTF_16);  的,但我的系式没有,真的要下最新版试试了。谢谢了
      

  6.   

    但是我用的就是 1.8版啊,gamebus() 你试过行吗?
      

  7.   

    csCell.setEncoding(HSSFCell.ENCODING_UTF_16); //设置cell编码解决中文高位字节截断csCell.setCellValue("中文测试");测试通过