| 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 java.util.Formatter;
|
|
|
20 |
import java.util.Map;
|
|
|
21 |
|
|
|
22 |
import org.apache.poi.hssf.util.HSSFColor;
|
|
|
23 |
import org.apache.poi.ss.usermodel.CellStyle;
|
|
|
24 |
import org.apache.poi.xssf.usermodel.XSSFCellStyle;
|
|
|
25 |
import org.apache.poi.xssf.usermodel.XSSFColor;
|
|
|
26 |
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
|
|
27 |
|
|
|
28 |
/**
|
|
|
29 |
* Implementation of {@link HtmlHelper} for XSSF files.
|
|
|
30 |
*
|
|
|
31 |
* @author Ken Arnold, Industrious Media LLC
|
|
|
32 |
*/
|
|
|
33 |
public class XSSFHtmlHelper implements HtmlHelper {
|
|
|
34 |
private final XSSFWorkbook wb;
|
|
|
35 |
|
|
|
36 |
private static final Map<Integer,HSSFColor> colors = HSSFColor.getIndexHash();
|
|
|
37 |
|
|
|
38 |
public XSSFHtmlHelper(XSSFWorkbook wb) {
|
|
|
39 |
this.wb = wb;
|
|
|
40 |
}
|
|
|
41 |
|
|
|
42 |
public void colorStyles(CellStyle style, Formatter out) {
|
|
|
43 |
XSSFCellStyle cs = (XSSFCellStyle) style;
|
|
|
44 |
styleColor(out, "background-color", cs.getFillForegroundXSSFColor());
|
|
|
45 |
styleColor(out, "text-color", cs.getFont().getXSSFColor());
|
|
|
46 |
}
|
|
|
47 |
|
|
|
48 |
private void styleColor(Formatter out, String attr, XSSFColor color) {
|
|
|
49 |
if (color == null || color.isAuto())
|
|
|
50 |
return;
|
|
|
51 |
|
|
|
52 |
byte[] rgb = color.getRgb();
|
|
|
53 |
if (rgb == null) {
|
|
|
54 |
return;
|
|
|
55 |
}
|
|
|
56 |
|
|
|
57 |
// This is done twice -- rgba is new with CSS 3, and browser that don't
|
|
|
58 |
// support it will ignore the rgba specification and stick with the
|
|
|
59 |
// solid color, which is declared first
|
|
|
60 |
out.format(" %s: #%02x%02x%02x;%n", attr, rgb[0], rgb[1], rgb[2]);
|
|
|
61 |
byte[] argb = color.getARgb();
|
|
|
62 |
if (argb == null) {
|
|
|
63 |
return;
|
|
|
64 |
}
|
|
|
65 |
out.format(" %s: rgba(0x%02x, 0x%02x, 0x%02x, 0x%02x);%n", attr,
|
|
|
66 |
argb[3], argb[0], argb[1], argb[2]);
|
|
|
67 |
}
|
|
|
68 |
}
|