import static org.junit.jupiter.api.Assertions.assertEquals;
import java.io.IOException;
+import java.io.InputStream;
import java.util.List;
import java.util.regex.Pattern;
SharedStringsTable stbl = new SharedStringsTable(parts.get(0));
ReadOnlySharedStringsTable rtbl = new ReadOnlySharedStringsTable(parts.get(0));
+ ReadOnlySharedStringsTable rtbl2;
+ try (InputStream stream = parts.get(0).getInputStream()){
+ rtbl2 = new ReadOnlySharedStringsTable(stream);
+ }
assertEquals(stbl.getCount(), rtbl.getCount());
assertEquals(stbl.getUniqueCount(), rtbl.getUniqueCount());
+ assertEquals(stbl.getUniqueCount(), rtbl2.getUniqueCount());
assertEquals(stbl.getCount(), stbl.getUniqueCount());
assertEquals(rtbl.getCount(), rtbl.getUniqueCount());
+ assertEquals(rtbl.getCount(), rtbl2.getUniqueCount());
for (int i = 0; i < stbl.getUniqueCount(); i++) {
RichTextString i1 = stbl.getItemAt(i);
- RichTextString i2 = rtbl.getItemAt(i);
- assertEquals(i1.getString(), i2.getString());
+ assertEquals(i1.getString(), rtbl.getItemAt(i).getString());
+ assertEquals(i1.getString(), rtbl2.getItemAt(i).getString());
}
}
}
package org.apache.poi.xssf.model;
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertFalse;
-import static org.junit.jupiter.api.Assertions.assertNotNull;
-import static org.junit.jupiter.api.Assertions.assertNull;
-import static org.junit.jupiter.api.Assertions.assertTrue;
-
import java.io.FileOutputStream;
import java.io.IOException;
+import java.io.InputStream;
import java.util.LinkedHashMap;
+import java.util.List;
import java.util.Locale;
import java.util.Map;
import org.apache.commons.codec.binary.Hex;
+import org.apache.poi.openxml4j.opc.PackagePart;
import org.apache.poi.ss.usermodel.FillPatternType;
import org.apache.poi.ss.util.CellReference;
import org.apache.poi.xssf.XSSFTestDataSamples;
import org.apache.poi.xssf.model.ThemesTable.ThemeElement;
-import org.apache.poi.xssf.usermodel.XSSFCell;
-import org.apache.poi.xssf.usermodel.XSSFCellStyle;
-import org.apache.poi.xssf.usermodel.XSSFColor;
-import org.apache.poi.xssf.usermodel.XSSFFont;
-import org.apache.poi.xssf.usermodel.XSSFRow;
-import org.apache.poi.xssf.usermodel.XSSFSheet;
-import org.apache.poi.xssf.usermodel.XSSFWorkbook;
+import org.apache.poi.xssf.usermodel.*;
import org.junit.jupiter.api.Test;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTColor;
+import static org.junit.jupiter.api.Assertions.*;
+
class TestThemesTable {
private static final String testFileComplex = "Themes2.xlsx";
// TODO .xls version available too, add HSSF support then check
void themedAndNonThemedColours() throws IOException {
try (XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook(testFileComplex)) {
XSSFSheet sheet = wb.getSheetAt(0);
+ ThemesTable themesTable = wb.getTheme();
+ XSSFColor color1 = themesTable.getThemeColor(0);
+ assertNotNull(color1);
+ assertNotEquals(0, color1.getRGB().length);
+ List<PackagePart> themeParts = wb.getPackage().getPartsByContentType(XSSFRelation.THEME.getContentType());
+ assertEquals(1, themeParts.size());
+ try (InputStream themeStream = themeParts.get(0).getInputStream()) {
+ ThemesTable themesTable2 = new ThemesTable(themeStream);
+ assertArrayEquals(color1.getRGB(), themesTable2.getThemeColor(0).getRGB());
+ }
String[] names = {"White", "Black", "Grey", "Dark Blue", "Blue", "Red", "Green"};
String[] explicitFHexes = {"FFFFFFFF", "FF000000", "FFC0C0C0", "FF002060",