jxl设置第一行单元格格式

jxl设置第一行单元格格式

WritableFont wf = new WritableFont(WritableFont.ARIAL,10,WritableFont.BOLD);

WritableCellFormat wcf = new WritableCellFormat(wf);

CellView cv = new CellView();
cv.setAutosize(true);
cv.setSize(1*256);

cv.setFormat(wcf);
sheet.setRowView(0,cv);

设置了字体为粗体,但是没有显示效果,请教,谢谢

[quote]setColumnView是可以用,setRowView还是没效果[/quote]
是这样的

来个更诡异的
[code="java"]import java.io.*;

import jxl.*;
import jxl.write.*;

public class JxlTest {
public static void main(String[] args) {
WritableWorkbook book = null;
try {
book = Workbook.createWorkbook(new File("d:/test.xls"));// 创建文件
WritableSheet sheet = book.createSheet("test", 0);// 创建工作表

        WritableFont wf = new WritableFont(WritableFont.TAHOMA,10,WritableFont.BOLD); 
        WritableCellFormat wcf = new WritableCellFormat(wf); 

        CellView cv = new CellView(); 
        cv.setAutosize(true); 
        cv.setSize(1*256); 

        Label label = new Label(0, 1,"测试01");
        sheet.addCell(label);

        cv.setFormat(wcf); 
        sheet.setRowView(0,cv); 
        sheet.setColumnView(0,cv); 

System.out.println(sheet.getRowView(0).getFormat()); //!!有木有发现是null。。。

        book.write();// 写数据
        book.close();

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

}[/code]
我之前给你发了jxl源码的链接,你看一下它的源码里setRowView和setColumnView的不同。。。个人觉得是jxl的问题

所以干脆给lable加上format吧
[code="java"]Label label = new Label(1, 1, "测试11", wcf);[/code]

你不是设置第一行么,怎么会用cellviow嘞,不是应该还是RowView的嚒

[code="java"]CellView cv = new CellView(); //!!![/code]

[code="java"]RowView rv = new RowView();
rv.setFormat(wcf);
sheet.setRowView(0, rv); [/code]

[code="java"]import java.io.*;

import jxl.*;
import jxl.write.*;

public class JxlTest {
public static void main(String[] args) {
WritableWorkbook book = null;
try {
book = Workbook.createWorkbook(new File("d:/test.xls"));// 创建文件
WritableSheet sheet = book.createSheet("test", 0);// 创建工作表

        WritableFont wf = new WritableFont(WritableFont.TAHOMA,10,WritableFont.BOLD); 
        WritableCellFormat wcf = new WritableCellFormat(wf); 

        CellView cv = new CellView(); 
        cv.setAutosize(true); 
        cv.setSize(1*256); 

        Label label = new Label(1, 1, "测试11",wcf);// 创建单元格Label(int col, int
        Label label1 = new Label(0, 1, "测试01");
        Label label2 = new Label(1, 0, "测试10");
        sheet.addCell(label);// 添加单元格到工作表中
        sheet.addCell(label1);
        sheet.addCell(label2);

        cv.setFormat(wcf); 
        sheet.setRowView(0,cv); 
        sheet.setColumnView(0,cv); 

        book.write();// 写数据
        book.close();

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

}[/code]
运行这么一段代码会发现setRowView对行是起作用的,看第一行,除了"测试01"之外其他都是TAHOMA bold的,但是文本写进去后格式又没了

但是setColumnView是可以用的

有空再看下源码,要是搞不定,暂时用Label label = new Label(1, 1, "测试11", wcf);给label加上格式吧

[quote]eclipse调试setRowView时,为什么source not found[/quote]
啊? 你是要对jxl的源码调试么?有下载他的源码包么? 如果要对jxl的代码进行调试,要设置jxl的源码位置的

要先下载源码解压,在eclipse的build path里选中jxl的jar包,然后有个参数是attatch xxx的,选择jar包的源码,就可以对jxl的jar包进行调试了