Thursday, August 14, 2008

Writing in MS Excel through Jxcell

In my previous articles of “Writing in MS Excel”, I gave you the overview of how you can write into it through POI package. There is another API available Jxcell, which will guide you the same thing, but in different way. You can download the latest version of Jxcell using following link:
http://www.jxcell.net/
The following code will guide you how to deal with MS Excel using Jxcell.

import com.jxcell.CellFormat;
import com.jxcell.TextWithFormat;
import com.jxcell.View;
import com.jxcell.designer.Designer;

import java.awt.*;

public class TextFormattingTest {

private void doTextFormatting(){
View m_view = new View();
try {
m_view.setText(0,0,"Hello, you are welcome!");
m_view.setColWidth(0, 36*256);
m_view.setRowHeight(0, 120*20);
CellFormat rangeStyle = m_view.getCellFormat();
rangeStyle.setOrientation((short)45);
m_view.setCellFormat(rangeStyle);
TextWithFormat[] tf = new TextWithFormat[4];
tf[0] = new TextWithFormat(m_view);
tf[1] = new TextWithFormat(m_view);
tf[2] = new TextWithFormat(m_view);
tf[3] = new TextWithFormat(m_view);
tf[0].setFontItalic(true);
tf[0].setStartPos(0);
tf[0].setFontColor(Color.BLUE.getRGB());
tf[1].setFontBold(true);
tf[1].setFontSize(16*20);
tf[1].setStartPos(7);
tf[2].setFontUnderline(true);
tf[2].setStartPos(11);
tf[2].setFontColor(Color.GREEN.getRGB());
tf[3].setFontSize(14*20);
tf[3].setStartPos(14);
m_view.setTextFormat(tf);
m_view.write("C:/TextFormatting.xls", View.eFileExcel);
Designer.newDesigner(m_view);
} catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String args[]) {
TextFormattingTest tft = new TextFormattingTest();
tft.doTextFormatting();
}
}






The next section will guide you how to create charts using Jxcell.

No comments:

Total Pageviews