| 8673 |
kshitij.so |
1 |
/* ====================================================================
|
|
|
2 |
Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
3 |
contributor license agreements. See the NOTICE file distributed with
|
|
|
4 |
this work for additional information regarding copyright ownership.
|
|
|
5 |
The ASF licenses this file to You under the Apache License, Version 2.0
|
|
|
6 |
(the "License"); you may not use this file except in compliance with
|
|
|
7 |
the License. You may obtain a copy of the License at
|
|
|
8 |
|
|
|
9 |
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
10 |
|
|
|
11 |
Unless required by applicable law or agreed to in writing, software
|
|
|
12 |
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
13 |
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
14 |
See the License for the specific language governing permissions and
|
|
|
15 |
limitations under the License.
|
|
|
16 |
==================================================================== */
|
|
|
17 |
package com.amazonaws.mws.samples;
|
|
|
18 |
|
|
|
19 |
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
|
|
|
20 |
import org.apache.poi.hssf.usermodel.HSSFPalette;
|
|
|
21 |
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
|
|
22 |
import org.apache.poi.hssf.util.HSSFColor;
|
|
|
23 |
import org.apache.poi.ss.usermodel.CellStyle;
|
|
|
24 |
|
|
|
25 |
import java.util.Formatter;
|
|
|
26 |
|
|
|
27 |
/**
|
|
|
28 |
* Implementation of {@link HtmlHelper} for HSSF files.
|
|
|
29 |
*
|
|
|
30 |
* @author Ken Arnold, Industrious Media LLC
|
|
|
31 |
*/
|
|
|
32 |
public class HSSFHtmlHelper implements HtmlHelper {
|
|
|
33 |
private final HSSFWorkbook wb;
|
|
|
34 |
private final HSSFPalette colors;
|
|
|
35 |
|
|
|
36 |
private static final HSSFColor HSSF_AUTO = new HSSFColor.AUTOMATIC();
|
|
|
37 |
|
|
|
38 |
public HSSFHtmlHelper(HSSFWorkbook wb) {
|
|
|
39 |
this.wb = wb;
|
|
|
40 |
// If there is no custom palette, then this creates a new one that is
|
|
|
41 |
// a copy of the default
|
|
|
42 |
colors = wb.getCustomPalette();
|
|
|
43 |
}
|
|
|
44 |
|
|
|
45 |
public void colorStyles(CellStyle style, Formatter out) {
|
|
|
46 |
HSSFCellStyle cs = (HSSFCellStyle) style;
|
|
|
47 |
out.format(" /* fill pattern = %d */%n", cs.getFillPattern());
|
|
|
48 |
styleColor(out, "background-color", cs.getFillForegroundColor());
|
|
|
49 |
styleColor(out, "color", cs.getFont(wb).getColor());
|
|
|
50 |
styleColor(out, "border-left-color", cs.getLeftBorderColor());
|
|
|
51 |
styleColor(out, "border-right-color", cs.getRightBorderColor());
|
|
|
52 |
styleColor(out, "border-top-color", cs.getTopBorderColor());
|
|
|
53 |
styleColor(out, "border-bottom-color", cs.getBottomBorderColor());
|
|
|
54 |
}
|
|
|
55 |
|
|
|
56 |
private void styleColor(Formatter out, String attr, short index) {
|
|
|
57 |
HSSFColor color = colors.getColor(index);
|
|
|
58 |
if (index == HSSF_AUTO.getIndex() || color == null) {
|
|
|
59 |
out.format(" /* %s: index = %d */%n", attr, index);
|
|
|
60 |
} else {
|
|
|
61 |
short[] rgb = color.getTriplet();
|
|
|
62 |
out.format(" %s: #%02x%02x%02x; /* index = %d */%n", attr, rgb[0],
|
|
|
63 |
rgb[1], rgb[2], index);
|
|
|
64 |
}
|
|
|
65 |
}
|
|
|
66 |
}
|