PageRenderTime 51ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/src/XLColorTest.java

https://bitbucket.org/manticoretrader/etltools
Java | 65 lines | 33 code | 10 blank | 22 comment | 4 complexity | aa5cdb3360caf13f65390496ade0595c MD5 | raw file
  1. import java.io.File;
  2. import java.io.IOException;
  3. import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
  4. import org.apache.poi.ss.usermodel.CellStyle;
  5. import org.apache.poi.ss.usermodel.Color;
  6. import org.apache.poi.ss.usermodel.IndexedColors;
  7. import org.apache.poi.ss.usermodel.Sheet;
  8. import org.apache.poi.ss.usermodel.Workbook;
  9. import org.apache.poi.ss.usermodel.WorkbookFactory;
  10. import org.apache.poi.xssf.model.StylesTable;
  11. import org.apache.poi.xssf.usermodel.XSSFCellStyle;
  12. import org.apache.poi.xssf.usermodel.XSSFColor;
  13. import org.apache.poi.xssf.usermodel.XSSFSheet;
  14. import org.apache.poi.xssf.usermodel.XSSFWorkbook;
  15. import org.apache.poi.xssf.usermodel.extensions.XSSFCellFill;
  16. /*
  17. * Copyright (C) 2015 are
  18. *
  19. * This program is free software: you can redistribute it and/or modify
  20. * it under the terms of the GNU General Public License as published by
  21. * the Free Software Foundation, either version 3 of the License, or
  22. * (at your option) any later version.
  23. *
  24. * This program is distributed in the hope that it will be useful,
  25. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  26. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  27. * GNU General Public License for more details.
  28. *
  29. * You should have received a copy of the GNU General Public License
  30. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  31. */
  32. /**
  33. *
  34. * @author are
  35. */
  36. public class XLColorTest {
  37. public static void main(String[] args) throws IOException, InvalidFormatException {
  38. XSSFWorkbook wb=new XSSFWorkbook(new File("/home/are/test1.xlsx"));
  39. XSSFSheet sheet=wb.getSheetAt(0);
  40. XSSFCellStyle cellStyle = sheet.getRow(0).getCell(0).getCellStyle();
  41. StylesTable stylesSource = wb.getStylesSource();
  42. for (int i=0; i<stylesSource.getNumCellStyles(); i++)
  43. if (stylesSource.getStyleAt(i).equals(cellStyle))
  44. System.out.println("Found cellstule with index " + i + " vs. " + cellStyle.getIndex());
  45. System.out.println("Fill ID: " + cellStyle.getCoreXf().getFillId());
  46. System.out.println("Index: " + sheet.getRow(0).getCell(0).getCellStyle().getIndex());
  47. //for (short i=0; i<stylesSource.getNumCellStyles(); i++) {
  48. XSSFCellFill fill = stylesSource.getFillAt(cellStyle.getIndex()+1);
  49. if (fill.getFillBackgroundColor()!=null)
  50. System.out.println("Index: " + cellStyle.getIndex() + " "+ fill.getFillBackgroundColor().getARGBHex());
  51. if (fill.getFillForegroundColor()!=null)
  52. System.out.println("Index: " +cellStyle.getIndex() + " "+ fill.getFillForegroundColor().getARGBHex());
  53. //}
  54. }
  55. }