You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

XSSFITestDataProvider.java 3.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. http://www.apache.org/licenses/LICENSE-2.0
  9. Unless required by applicable law or agreed to in writing, software
  10. distributed under the License is distributed on an "AS IS" BASIS,
  11. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. See the License for the specific language governing permissions and
  13. limitations under the License.
  14. ==================================================================== */
  15. package org.apache.poi.xssf;
  16. import org.apache.poi.POIDataSamples;
  17. import org.apache.poi.ss.ITestDataProvider;
  18. import org.apache.poi.ss.SpreadsheetVersion;
  19. import org.apache.poi.ss.usermodel.FormulaEvaluator;
  20. import org.apache.poi.ss.usermodel.Sheet;
  21. import org.apache.poi.ss.usermodel.Workbook;
  22. import org.apache.poi.xssf.usermodel.XSSFFormulaEvaluator;
  23. import org.apache.poi.xssf.usermodel.XSSFWorkbook;
  24. public final class XSSFITestDataProvider implements ITestDataProvider {
  25. public static final XSSFITestDataProvider instance = new XSSFITestDataProvider();
  26. private XSSFITestDataProvider() {
  27. // enforce singleton
  28. }
  29. @Override
  30. public XSSFWorkbook openSampleWorkbook(String sampleFileName) {
  31. return XSSFTestDataSamples.openSampleWorkbook(sampleFileName);
  32. }
  33. @Override
  34. public XSSFWorkbook writeOutAndReadBack(Workbook original) {
  35. if(!(original instanceof XSSFWorkbook)) {
  36. throw new IllegalArgumentException("Expected an instance of XSSFWorkbook, but had " + original.getClass());
  37. }
  38. return XSSFTestDataSamples.writeOutAndReadBack((XSSFWorkbook)original);
  39. }
  40. @Override
  41. public XSSFWorkbook createWorkbook() {
  42. return new XSSFWorkbook();
  43. }
  44. //************ SXSSF-specific methods ***************//
  45. @Override
  46. public XSSFWorkbook createWorkbook(int rowAccessWindowSize) {
  47. return createWorkbook();
  48. }
  49. @Override
  50. public void trackAllColumnsForAutosizing(Sheet sheet) {}
  51. //************ End SXSSF-specific methods ***************//
  52. @Override
  53. public FormulaEvaluator createFormulaEvaluator(Workbook wb) {
  54. return new XSSFFormulaEvaluator((XSSFWorkbook) wb);
  55. }
  56. @Override
  57. public byte[] getTestDataFileContent(String fileName) {
  58. return POIDataSamples.getSpreadSheetInstance().readFile(fileName);
  59. }
  60. @Override
  61. public SpreadsheetVersion getSpreadsheetVersion(){
  62. return SpreadsheetVersion.EXCEL2007;
  63. }
  64. @Override
  65. public String getStandardFileNameExtension() {
  66. return "xlsx";
  67. }
  68. }