JXCELL实例学习与研究(五) 之 斜体的设置以及字符串中颜色的显示

来源:互联网 发布:ktv调音软件下载 编辑:程序博客网 时间:2024/04/28 20:31

可以针对指定位置的字符串,设置其颜色


import com.jxcell.CellFormat;import com.jxcell.View;import com.jxcell.designer.Designer;import java.awt.*;public class TextFormattingTest{    public static void main(String args[])    {        View m_view = new View();        try        {            //set data            String text = "Hello, you are welcome!";            m_view.setText(0,0,text);            m_view.setColWidth(0, 36*256);            m_view.setRowHeight(0, 120*20);            //text orientation            CellFormat rangeStyle = m_view.getCellFormat();            rangeStyle.setOrientation((short)45);            m_view.setCellFormat(rangeStyle);            //multi text selection format            m_view.setTextSelection(0, 6);            CellFormat cfmt = m_view.getCellFormat();            cfmt.setFontItalic(true);            cfmt.setFontColor(Color.BLUE.getRGB());            m_view.setCellFormat(cfmt);            m_view.setTextSelection(7, 10);            cfmt = m_view.getCellFormat();            cfmt.setFontBold(true);            cfmt.setFontSize(16*20);            m_view.setCellFormat(cfmt);            m_view.setTextSelection(11, 13);            cfmt = m_view.getCellFormat();            cfmt.setFontUnderline(CellFormat.UnderlineSingle);            cfmt.setFontColor(Color.GREEN.getRGB());            m_view.setCellFormat(cfmt);            m_view.setTextSelection(14, text.length()-1);            cfmt = m_view.getCellFormat();            cfmt.setFontSize(14*20);            m_view.setCellFormat(cfmt);            m_view.setSelection(0, 5, 65535, 5);            cfmt = m_view.getCellFormat();            cfmt.setMergeCells(true);            m_view.setCellFormat(cfmt);            m_view.write("./TextFormatting.xls");            Designer.newDesigner(m_view);        }        catch (Exception e)        {            e.printStackTrace();        }    }}