📄 write.java
字号:
l = new Label(2, 5, "hh:mm:ss");
s.addCell(l);
dt = new DateTime(3, 5, date, cf1);
s.addCell(dt);
df = new DateFormat("H:mm:ss a");
cf1 = new WritableCellFormat(df);
l = new Label(2, 5, "H:mm:ss a");
s.addCell(l);
dt = new DateTime(3, 5, date, cf1);
s.addCell(dt);
df = new DateFormat("mm:ss.SSS");
cf1 = new WritableCellFormat(df);
l = new Label(2, 6, "mm:ss.SSS");
s.addCell(l);
dt = new DateTime(3, 6, date, cf1);
s.addCell(dt);
// Check out the zero date ie. 1 Jan 1900
l = new Label(0,16,"Zero date " + sdf.format(date2),
wrappedText);
s.addCell(l);
cf1 = new WritableCellFormat(DateFormats.FORMAT9);
dt = new DateTime(0,17,date2, cf1);
s.addCell(dt);
// Check out the zero date + 1 ie. 2 Jan 1900
l = new Label(3,16,"Zero date + 1 " + sdf.format(date5),
wrappedText);
s.addCell(l);
cf1 = new WritableCellFormat(DateFormats.FORMAT9);
dt = new DateTime(3,17,date5, cf1);
s.addCell(dt);
// Check out the 1 Jan 1901
l = new Label(3,19, sdf.format(date6),
wrappedText);
s.addCell(l);
cf1 = new WritableCellFormat(DateFormats.FORMAT9);
dt = new DateTime(3,20,date6, cf1);
s.addCell(dt);
// Check out the 31 May 1900
l = new Label(3,22, sdf.format(date7),
wrappedText);
s.addCell(l);
cf1 = new WritableCellFormat(DateFormats.FORMAT9);
dt = new DateTime(3,23, date7, cf1);
s.addCell(dt);
// Check out 1 Feb 1900
l = new Label(3,25, sdf.format(date8),
wrappedText);
s.addCell(l);
cf1 = new WritableCellFormat(DateFormats.FORMAT9);
dt = new DateTime(3,26, date8, cf1);
s.addCell(dt);
// Check out 31 Jan 1900
l = new Label(3,28, sdf.format(date9),
wrappedText);
s.addCell(l);
cf1 = new WritableCellFormat(DateFormats.FORMAT9);
dt = new DateTime(3,29, date9, cf1);
s.addCell(dt);
// Check out 31 Jan 1900
l = new Label(3,28, sdf.format(date9),
wrappedText);
s.addCell(l);
cf1 = new WritableCellFormat(DateFormats.FORMAT9);
dt = new DateTime(3,29, date9, cf1);
s.addCell(dt);
// Check out 1 Mar 1900
l = new Label(3,31, sdf.format(date10),
wrappedText);
s.addCell(l);
cf1 = new WritableCellFormat(DateFormats.FORMAT9);
dt = new DateTime(3,32, date10, cf1);
s.addCell(dt);
// Check out 27 Feb 1900
l = new Label(3,34, sdf.format(date11),
wrappedText);
s.addCell(l);
cf1 = new WritableCellFormat(DateFormats.FORMAT9);
dt = new DateTime(3,35, date11, cf1);
s.addCell(dt);
// Check out 28 Feb 1900
l = new Label(3,37, sdf.format(date12),
wrappedText);
s.addCell(l);
cf1 = new WritableCellFormat(DateFormats.FORMAT9);
dt = new DateTime(3,38, date12, cf1);
s.addCell(dt);
// Check out the zero date ie. 1 Jan 1970
l = new Label(0,19,"Zero UTC date " + sdf.format(date3),
wrappedText);
s.addCell(l);
cf1 = new WritableCellFormat(DateFormats.FORMAT9);
dt = new DateTime(0,20,date3, cf1);
s.addCell(dt);
// Check out the WWI armistice day ie. 11 am, Nov 11, 1918
l = new Label(0,22,"Armistice date " + sdf.format(date4),
wrappedText);
s.addCell(l);
cf1 = new WritableCellFormat(DateFormats.FORMAT9);
dt = new DateTime(0,23,date4, cf1);
s.addCell(dt);
}
/**
* Adds cells to the specified sheet which test the various label formatting
* styles, such as different fonts, different sizes and bold, underline etc.
*
* @param s1
*/
private void writeLabelFormatSheet(WritableSheet s1) throws WriteException
{
s1.setColumnView(0, 60);
Label lr = new Label(0,0, "Arial Fonts");
s1.addCell(lr);
lr = new Label(1,0, "10pt");
s1.addCell(lr);
lr = new Label(2, 0, "Normal");
s1.addCell(lr);
lr = new Label(3, 0, "12pt");
s1.addCell(lr);
WritableFont arial12pt = new WritableFont(WritableFont.ARIAL, 12);
WritableCellFormat arial12format = new WritableCellFormat(arial12pt);
arial12format.setWrap(true);
lr = new Label(4, 0, "Normal", arial12format);
s1.addCell(lr);
WritableFont arial10ptBold = new WritableFont
(WritableFont.ARIAL, 10, WritableFont.BOLD);
WritableCellFormat arial10BoldFormat = new WritableCellFormat
(arial10ptBold);
lr = new Label(2, 2, "BOLD", arial10BoldFormat);
s1.addCell(lr);
WritableFont arial12ptBold = new WritableFont
(WritableFont.ARIAL, 12, WritableFont.BOLD);
WritableCellFormat arial12BoldFormat = new WritableCellFormat
(arial12ptBold);
lr = new Label(4, 2, "BOLD", arial12BoldFormat);
s1.addCell(lr);
WritableFont arial10ptItalic = new WritableFont
(WritableFont.ARIAL, 10, WritableFont.NO_BOLD, true);
WritableCellFormat arial10ItalicFormat = new WritableCellFormat
(arial10ptItalic);
lr = new Label(2, 4, "Italic", arial10ItalicFormat);
s1.addCell(lr);
WritableFont arial12ptItalic = new WritableFont
(WritableFont.ARIAL, 12, WritableFont.NO_BOLD, true);
WritableCellFormat arial12ptItalicFormat = new WritableCellFormat
(arial12ptItalic);
lr = new Label(4, 4, "Italic", arial12ptItalicFormat);
s1.addCell(lr);
WritableFont times10pt = new WritableFont(WritableFont.TIMES, 10);
WritableCellFormat times10format = new WritableCellFormat(times10pt);
lr = new Label(0, 7, "Times Fonts", times10format);
s1.addCell(lr);
lr = new Label(1, 7, "10pt", times10format);
s1.addCell(lr);
lr = new Label(2, 7, "Normal", times10format);
s1.addCell(lr);
lr = new Label(3, 7, "12pt", times10format);
s1.addCell(lr);
WritableFont times12pt = new WritableFont(WritableFont.TIMES, 12);
WritableCellFormat times12format = new WritableCellFormat(times12pt);
lr = new Label(4, 7, "Normal", times12format);
s1.addCell(lr);
WritableFont times10ptBold = new WritableFont
(WritableFont.TIMES, 10, WritableFont.BOLD);
WritableCellFormat times10BoldFormat = new WritableCellFormat
(times10ptBold);
lr = new Label(2, 9, "BOLD", times10BoldFormat);
s1.addCell(lr);
WritableFont times12ptBold = new WritableFont
(WritableFont.TIMES, 12, WritableFont.BOLD);
WritableCellFormat times12BoldFormat = new WritableCellFormat
(times12ptBold);
lr = new Label(4, 9, "BOLD", times12BoldFormat);
s1.addCell(lr);
// The underline styles
s1.setColumnView(6, 22);
s1.setColumnView(7, 22);
s1.setColumnView(8, 22);
s1.setColumnView(9, 22);
lr = new Label(0, 11, "Underlining");
s1.addCell(lr);
WritableFont arial10ptUnderline = new WritableFont
(WritableFont.ARIAL,
WritableFont.DEFAULT_POINT_SIZE,
WritableFont.NO_BOLD,
false,
UnderlineStyle.SINGLE);
WritableCellFormat arialUnderline = new WritableCellFormat
(arial10ptUnderline);
lr = new Label(6,11, "Underline", arialUnderline);
s1.addCell(lr);
WritableFont arial10ptDoubleUnderline = new WritableFont
(WritableFont.ARIAL,
WritableFont.DEFAULT_POINT_SIZE,
WritableFont.NO_BOLD,
false,
UnderlineStyle.DOUBLE);
WritableCellFormat arialDoubleUnderline = new WritableCellFormat
(arial10ptDoubleUnderline);
lr = new Label(7,11, "Double Underline", arialDoubleUnderline);
s1.addCell(lr);
WritableFont arial10ptSingleAcc = new WritableFont
(WritableFont.ARIAL,
WritableFont.DEFAULT_POINT_SIZE,
WritableFont.NO_BOLD,
false,
UnderlineStyle.SINGLE_ACCOUNTING);
WritableCellFormat arialSingleAcc = new WritableCellFormat
(arial10ptSingleAcc);
lr = new Label(8,11, "Single Accounting Underline", arialSingleAcc);
s1.addCell(lr);
WritableFont arial10ptDoubleAcc = new WritableFont
(WritableFont.ARIAL,
WritableFont.DEFAULT_POINT_SIZE,
WritableFont.NO_BOLD,
false,
UnderlineStyle.DOUBLE_ACCOUNTING);
WritableCellFormat arialDoubleAcc = new WritableCellFormat
(arial10ptDoubleAcc);
lr = new Label(9,11, "Double Accounting Underline", arialDoubleAcc);
s1.addCell(lr);
WritableFont times14ptBoldUnderline = new WritableFont
(WritableFont.TIMES,
14,
WritableFont.BOLD,
false,
UnderlineStyle.SINGLE);
WritableCellFormat timesBoldUnderline = new WritableCellFormat
(times14ptBoldUnderline);
lr = new Label(6,12, "Times 14 Bold Underline", timesBoldUnderline);
s1.addCell(lr);
WritableFont arial18ptBoldItalicUnderline = new WritableFont
(WritableFont.ARIAL,
18,
WritableFont.BOLD,
true,
UnderlineStyle.SINGLE);
WritableCellFormat arialBoldItalicUnderline = new WritableCellFormat
(arial18ptBoldItalicUnderline);
lr = new Label(6,13, "Arial 18 Bold Italic Underline",
arialBoldItalicUnderline);
s1.addCell(lr);
lr = new Label(0, 15, "Script styles");
s1.addCell(lr);
WritableFont superscript = new WritableFont
(WritableFont.ARIAL,
WritableFont.DEFAULT_POINT_SIZE,
WritableFont.NO_BOLD,
false,
UnderlineStyle.NO_UNDERLINE,
Colour.BLACK,
ScriptStyle.SUPERSCRIPT);
WritableCellFormat superscriptFormat = new WritableCellFormat
(superscript);
lr = new Label(1,15, "superscript", superscriptFormat);
s1.addCell(lr);
WritableFont subscript = new WritableFont
(WritableFont.ARIAL,
WritableFont.DEFAULT_POINT_SIZE,
WritableFont.NO_BOLD,
false,
UnderlineStyle.NO_UNDERLINE,
Colour.BLACK,
ScriptStyle.SUBSCRIPT);
WritableCellFormat subscriptFormat = new WritableCellFormat
(subscript);
lr = new Label(2,15, "subscript", subscriptFormat);
s1.addCell(lr);
lr = new Label(0, 17, "Colours");
s1.addCell(lr);
WritableFont red = new WritableFont(WritableFont.ARIAL,
WritableFont.DEFAULT_POINT_SIZE,
WritableFont.NO_BOLD,
false,
UnderlineStyle.NO_UNDERLINE,
Colour.RED);
WritableCellFormat redFormat = new WritableCellFormat(red);
lr = new Label(2, 17, "Red", redFormat);
s1.addCell(lr);
WritableFont blue = new WritableFont(WritableFont.ARIAL,
WritableFont.DEFAULT_POINT_SIZE,
WritableFont.NO_BOLD,
false,
UnderlineStyle.NO_UNDERLINE,
Colour.BLUE);
WritableCellFormat blueFormat = new WritableCellFormat(blue);
lr = new Label(2, 18, "Blue", blueFormat);
s1.addCell(lr);
WritableFont lime = new WritableFont(WritableFont.ARIAL);
lime.setColour(Colour.LIME);
WritableCellFormat limeFormat = new WritableCellFormat(lime);
limeFormat.setWrap(true);
lr = new Label(4, 18, "Modified palette - was lime, now red", limeFormat);
s1.addCell(lr);
WritableCellFormat greyBackground = new WritableCellFormat();
greyBackground.setWrap(true);
greyBackground.setBackground(Colour.GRAY_50);
lr = new Label(2, 19, "Grey background", greyBackground);
s1.addCell(lr);
WritableFont yellow = new WritableFont(WritableFont.ARIAL,
WritableFont.DEFAULT_POINT_SIZE,
WritableFont.NO_BOLD,
false,
UnderlineStyle.NO_UNDERLINE,
Colour.YELLOW);
WritableCellFormat yellowOnBlue = new WritableCellFormat(yellow);
yellowOnBlue.setWrap(true);
yellowOnBlue.setBackground(Colour.BLUE);
lr = new Label(2, 20, "Blue background, yellow foreground", yellowOnBlue);
s1.addCell(lr);
lr = new Label(0, 22, "Null label");
s1.addCell(lr);
lr = new Label(2, 22, null);
s1.addCell(lr);
lr = new Label(0, 24,
"A very long label, more than 255 characters\012" +
"Rejoice O shores\012" +
"Sing O bells\012" +
"But I with mournful tread\012" +
"Walk the deck my captain lies\012" +
"Fallen cold and dead\012"+
"Summer surprised, coming over the Starnbergersee\012" +
"With a shower of rain. We stopped in the Colonnade\012" +
"A very long label, more than 255 characters\012" +
"Rejoice O shores\012" +
"Sing O bells\012" +
"But I with mournful tread\012" +
"Walk the deck my captain lies\012" +
"Fallen cold and dead\012"+
"Summer surprised, coming over the Starnbergersee\012" +
"With a shower of rain. We stopped in the Colonnade\012" + "A very long label, more than 255 characters\012" +
"Rejoice O shores\012" +
"Sing O bells\012" +
"But I with mournful tread\012" +
"Walk the deck my captain lies\012" +
"Fallen cold and dead\012"+
"Summer surprised, coming over the Starnbergersee\012" +
"With a shower of rain. We stopped in the Colonnade\012" + "A very long label, more than 255 characters\012" +
"Rejoice O shores\012" +
"Sing O bells\012" +
"But I with mournful tread\012" +
"Walk the deck my captain lies\012" +
"Fallen cold and dead\012"+
"Summer surprised, coming over the Starnbergersee\012" +
"With a shower of rain. We stopped in the Colonnade\012" +
"And sat and drank coffee an talked for an hour\012",
arial12format);
s1.addCell(lr);
WritableCellFormat vertical = new WritableCellFormat();
vertical.setOrientation(Orientation.VERTICAL);
lr = new Label(0, 26, "Vertical orientation", vertical);
s1.addCell(lr);
WritableCellFormat plus_90 = new WritableCellFormat();
plus_90.setOrientation(Orientation.PLUS_90);
lr = new Label(1, 26, "Plus 90", plus_90);
s1.addCell(lr);
WritableCellFormat minus_90 = new WritableCellFormat();
minus_90.setOrientation(Orientation.MINUS_90);
lr = new Label(2, 26, "Minus 90", minus_90);
s1.addCell(lr);
lr = new Label(0, 28, "Modified row height");
s1.addCell(lr);
s1.setRowView(28, 24);
lr = new Label(0, 29, "Collapsed row");
s1.addCell(lr);
s1.setRowView(29, true);
// Write hyperlinks
try
{
Label l = new Label(0, 30, "Hyperlink to home page");
s1.addCell(l);
URL url = new URL("http://www.andykhan.com/jexcelapi");
WritableHyperlink wh = new WritableHyperlink(0, 30, 8, 31, url);
s1.addHyperlink(wh);
// The below hyperlink clashes with above
WritableHyperlink wh2 = new WritableHyperlink(7, 30, 9, 31, url);
s1.addHyperlink(wh2);
l = new Label(4, 2, "File hyperlink to documentation");
s1.addCell(l);
File file = new File("../jexcelapi/docs/index.html");
wh = new WritableHyperlink(0, 32, 8, 32, file);
s1.addHyperlink(wh);
// Add a hyperlink to another cell on this sheet
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -