/**
* Demonstrates how you can extract embedded data from a .xls file
*/
-@SuppressWarnings({"java:S106","java:S4823"})
+@SuppressWarnings({"java:S106","java:S4823","java:S1192"})
public final class EmbeddedObjects {
private EmbeddedObjects() {}
import org.apache.poi.hwpf.usermodel.Paragraph;
import org.apache.poi.hwpf.usermodel.Range;
+@SuppressWarnings({"java:S106","java:S4823"})
public final class Word2Forrest
{
Writer _out;
* 2mm have been noted in testing. Further investigation will
* continue to rectify this issue.
*/
+@SuppressWarnings({"java:S106","java:S4823"})
public class AddDimensionedImage {
// Four constants that determine how - and indeed whether - the rows
*
* @author Yegor Kozlov
*/
-@SuppressWarnings("java:S1192")
-public class BusinessPlan {
+@SuppressWarnings({"java:S106","java:S4823","java:S1192"})
+public final class BusinessPlan {
private static final String[] titles = {
"ID", "Project Name", "Owner", "Days", "Start", "End"};
null, null, null, null, null, "x", null, null, null, null, null},
};
+ private BusinessPlan() {}
+
public static void main(String[] args) throws Exception {
Workbook wb;
package org.apache.poi.ss.examples;
-import org.apache.poi.xssf.usermodel.*;
-import org.apache.poi.ss.util.CellRangeAddress;
-import org.apache.poi.ss.usermodel.*;
-import org.apache.poi.ss.usermodel.Font;
-import org.apache.poi.hssf.usermodel.HSSFWorkbook;
-
import java.io.FileOutputStream;
import java.util.Calendar;
-import java.util.Map;
import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
+import org.apache.poi.ss.usermodel.BorderStyle;
+import org.apache.poi.ss.usermodel.Cell;
+import org.apache.poi.ss.usermodel.CellStyle;
+import org.apache.poi.ss.usermodel.FillPatternType;
+import org.apache.poi.ss.usermodel.Font;
+import org.apache.poi.ss.usermodel.HorizontalAlignment;
+import org.apache.poi.ss.usermodel.IndexedColors;
+import org.apache.poi.ss.usermodel.PrintSetup;
+import org.apache.poi.ss.usermodel.Row;
+import org.apache.poi.ss.usermodel.Sheet;
+import org.apache.poi.ss.usermodel.VerticalAlignment;
+import org.apache.poi.ss.usermodel.Workbook;
+import org.apache.poi.ss.util.CellRangeAddress;
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
/**
* A monthly calendar created using Apache POI. Each month is on a separate sheet.
*
* @author Yegor Kozlov
*/
-public class CalendarDemo {
+@SuppressWarnings({"java:S106","java:S4823","java:S1192"})
+public final class CalendarDemo {
private static final String[] days = {
"Sunday", "Monday", "Tuesday",
"January", "February", "March","April", "May", "June","July", "August",
"September","October", "November", "December"};
+ private CalendarDemo() {}
+
public static void main(String[] args) throws Exception {
Calendar calendar = Calendar.getInstance();
/**
* Demonstrates how to read excel styles for cells
*/
-public class CellStyleDetails {
+@SuppressWarnings({"java:S106","java:S4823"})
+public final class CellStyleDetails {
+ private CellStyleDetails() {}
+
public static void main(String[] args) throws Exception {
if(args.length == 0) {
throw new IllegalArgumentException("Filename must be given");
}
-
+
try (Workbook wb = WorkbookFactory.create(new File(args[0]))) {
DataFormatter formatter = new DataFormatter();
}
}
}
-
+
private static String renderColor(Color color) {
if(color instanceof HSSFColor) {
return ((HSSFColor)color).getHexString();
* http://www.contextures.com/xlcondformat03.html
* </p>
*/
-@SuppressWarnings("java:S1192")
-public class ConditionalFormats {
+@SuppressWarnings({"java:S106","java:S4823","java:S1192"})
+public final class ConditionalFormats {
+
+ private ConditionalFormats() {}
/**
* generates a sample workbook with conditional formatting,
/**
* Excel Border Drawing - examples
- *
+ *
* <p>
* Partly based on the code snippets from
* org.apache.poi.ss.examples.ConditionalFormats
* </p>
*/
-public class DrawingBorders {
+@SuppressWarnings({"java:S106","java:S4823"})
+public final class DrawingBorders {
+
+ private DrawingBorders() {}
public static void main(String[] args) throws IOException {
try (Workbook wb = (args.length > 0 && args[0].equals("-xls"))
* }
* </pre>
*/
-@SuppressWarnings("java:S1192")
+@SuppressWarnings({"java:S106","java:S4823","java:S1192"})
public class ExcelComparator {
private static final String CELL_DATA_DOES_NOT_MATCH = "Cell Data does not Match ::";
* Loads embedded resources from Workbooks. Code taken from the website:
* https://poi.apache.org/spreadsheet/quick-guide.html#Embedded
*/
-public class LoadEmbedded {
- public static void main(String[] args) throws IOException, EncryptedDocumentException, OpenXML4JException, XmlException {
+@SuppressWarnings({"java:S106","java:S4823"})
+public final class LoadEmbedded {
+ private LoadEmbedded() {}
+
+ public static void main(String[] args) throws IOException, EncryptedDocumentException, OpenXML4JException, XmlException {
Workbook wb = WorkbookFactory.create(new File(args[0]));
loadEmbedded(wb);
}
-
+
public static void loadEmbedded(Workbook wb) throws IOException, InvalidFormatException, OpenXML4JException, XmlException {
if (wb instanceof HSSFWorkbook) {
loadEmbedded((HSSFWorkbook)wb);
throw new IllegalArgumentException(wb.getClass().getName());
}
}
-
+
public static void loadEmbedded(HSSFWorkbook workbook) throws IOException {
for (HSSFObjectData obj : workbook.getAllEmbeddedObjects()) {
//the OLE2 Class Name of the object
}
}
}
-
+
public static void loadEmbedded(XSSFWorkbook workbook) throws IOException, InvalidFormatException, OpenXML4JException, XmlException {
for (PackagePart pPart : workbook.getAllEmbeddedParts()) {
String contentType = pPart.getContentType();
*
* @author Yegor Kozlov
*/
-@SuppressWarnings("java:S1192")
-public class LoanCalculator {
+@SuppressWarnings({"java:S106","java:S4823","java:S1192"})
+public final class LoanCalculator {
+
+ private LoanCalculator() {}
public static void main(String[] args) throws Exception {
Workbook wb;
import org.apache.poi.xssf.streaming.SXSSFWorkbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
-@SuppressWarnings("java:S1192")
-public class SSPerformanceTest {
+@SuppressWarnings({"java:S106","java:S4823","java:S1192"})
+public final class SSPerformanceTest {
+ private SSPerformanceTest() {}
+
public static void main(String[] args) throws IOException {
if (args.length < 4) {
usage("need at least four command arguments");
*
* @author Yegor Kozlov
*/
-@SuppressWarnings("java:S1192")
-public class TimesheetDemo {
+@SuppressWarnings({"java:S106","java:S4823","java:S1192"})
+public final class TimesheetDemo {
private static final String[] titles = {
"Person", "ID", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun",
"Total\nHrs", "Overtime\nHrs", "Regular\nHrs"
};
- private static Object[][] sample_data = {
+ private static final Object[][] sample_data = {
{"Yegor Kozlov", "YK", 5.0, 8.0, 10.0, 5.0, 5.0, 7.0, 6.0},
{"Gisella Bronzetti", "GB", 4.0, 3.0, 1.0, 3.5, null, null, 4.0},
};
+ private TimesheetDemo() {}
+
public static void main(String[] args) throws Exception {
Workbook wb;
* either obeying Excel's or UNIX formatting
* conventions.
*/
+@SuppressWarnings({"java:S106","java:S4823","java:S1192"})
public class ToCSV {
private Workbook workbook;
* files using Apache POI, along with how to handle errors whilst
* doing so.
*/
+@SuppressWarnings({"java:S106","java:S4823","java:S1192"})
public class CheckFunctionsSupported {
public static void main(String[] args) throws Exception {
if (args.length < 1) {
}
}
- private Workbook workbook;
- private FormulaEvaluator evaluator;
+ private final Workbook workbook;
+ private final FormulaEvaluator evaluator;
public CheckFunctionsSupported(Workbook workbook) {
this.workbook = workbook;
this.evaluator = workbook.getCreationHelper().createFormulaEvaluator();
==================================================================== */
package org.apache.poi.ss.examples.formula;
-import java.io.File ;
+import java.io.File;
-import org.apache.poi.ss.formula.functions.FreeRefFunction ;
-import org.apache.poi.ss.formula.udf.DefaultUDFFinder ;
-import org.apache.poi.ss.formula.udf.UDFFinder ;
+import org.apache.poi.ss.formula.functions.FreeRefFunction;
+import org.apache.poi.ss.formula.udf.DefaultUDFFinder;
+import org.apache.poi.ss.formula.udf.UDFFinder;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellValue;
import org.apache.poi.ss.usermodel.FormulaEvaluator;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.usermodel.WorkbookFactory;
-import org.apache.poi.ss.util.CellReference ;
+import org.apache.poi.ss.util.CellReference;
/**
* An example class of how to invoke a User Defined Function for a given
* XLS instance using POI's UDFFinder implementation.
*/
-public class UserDefinedFunctionExample {
+@SuppressWarnings({"java:S106","java:S4823","java:S1192"})
+public final class UserDefinedFunctionExample {
+
+ private UserDefinedFunctionExample() {}
+
+ public static void main(String[] args ) throws Exception {
- public static void main( String[] args ) throws Exception {
-
if( args.length != 2 ) {
// e.g. src/examples/src/org/apache/poi/ss/examples/formula/mortgage-calculation.xls Sheet1!B4
System.out.println( "usage: UserDefinedFunctionExample fileName cellId" ) ;
return;
}
-
+
System.out.println( "fileName: " + args[0] ) ;
System.out.println( "cell: " + args[1] ) ;
-
+
File workbookFile = new File( args[0] ) ;
try (Workbook workbook = WorkbookFactory.create(workbookFile, null, true)) {
* This example shows how to display a spreadsheet in HTML using the classes for
* spreadsheet display.
*/
-@SuppressWarnings("java:S1192")
-public class ToHtml {
+@SuppressWarnings({"java:S106","java:S4823","java:S1192"})
+public final class ToHtml {
private final Workbook wb;
private final Appendable output;
private boolean completeHTML;
/**
* Build a bar chart from a template pptx
*/
+@SuppressWarnings({"java:S106","java:S4823","java:S1192"})
public final class BarChartDemo {
private BarChartDemo() {}
/**
* Build a chart without reading template file
*/
+@SuppressWarnings({"java:S106","java:S4823","java:S1192"})
public final class ChartFromScratch {
private ChartFromScratch() {}
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- * ====================================================================
+ * ====================================================================
*/
package org.apache.poi.xslf.usermodel;
import java.io.InputStream;
import java.io.PrintStream;
-import org.apache.poi.openxml4j.exceptions.OpenXML4JException;
import org.apache.poi.openxml4j.opc.PackagePart;
/**
* Demonstrates how you can extract data from a .pptx file
*/
+@SuppressWarnings({"java:S106","java:S4823","java:S1192"})
public final class DataExtraction {
private DataExtraction() {}
- public static void main(String[] args) throws IOException, OpenXML4JException {
+ public static void main(String[] args) throws IOException {
PrintStream out = System.out;
out.println("Input file is required");
return;
}
-
+
FileInputStream is = new FileInputStream(args[0]);
try (XMLSlideShow ppt = new XMLSlideShow(is)) {
is.close();
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- * ====================================================================
+ * ====================================================================
*/
package org.apache.poi.xslf.usermodel;
/**
* Merge multiple pptx presentations together
*/
+@SuppressWarnings({"java:S106","java:S4823","java:S1192"})
public final class MergePresentations {
private MergePresentations() {}
/**
* Build a pie chart from a template pptx
*/
+@SuppressWarnings({"java:S106","java:S4823","java:S1192"})
public final class PieChartDemo {
private PieChartDemo() {}
/**
* Reading a .pptx presentation and printing basic shape properties
*/
+@SuppressWarnings({"java:S106","java:S4823","java:S1192"})
public final class Step1 {
private Step1() {}
* For a more advanced implementation of SAX event parsing
* of XLSX files, see {@link XSSFEventBasedExcelExtractor}
* and {@link XSSFSheetXMLHandler}. Note that for many cases,
- * it may be possible to simply use those with a custom
+ * it may be possible to simply use those with a custom
* {@link SheetContentsHandler} and no SAX code needed of
* your own!
*/
+@SuppressWarnings({"java:S106","java:S4823","java:S1192"})
public class XLSX2CSV {
/**
* Uses the XSSF Event SAX helpers to do most of the work
private boolean firstCellOfRow;
private int currentRow = -1;
private int currentCol = -1;
-
+
private void outputMissingRows(int number) {
for (int i=0; i<number; i++) {
for (int j=0; j<minColumns; j++) {
output.append(',');
}
currentCol = thisCol;
-
+
// Number or string?
try {
//noinspection ResultOfMethodCallIgnored
public void processSheet(
Styles styles,
SharedStrings strings,
- SheetContentsHandler sheetHandler,
+ SheetContentsHandler sheetHandler,
InputStream sheetInputStream) throws IOException, SAXException {
DataFormatter formatter = new DataFormatter();
InputSource sheetSource = new InputSource(sheetInputStream);
* See {@link XLSX2CSV} for a fuller example of doing
* XSLX processing with the XSSF Event code.
*/
+@SuppressWarnings({"java:S106","java:S4823","java:S1192"})
public class FromHowTo {
public void processFirstSheet(String filename) throws Exception {
try (OPCPackage pkg = OPCPackage.open(filename, PackageAccess.READ)) {
* <li><code>AesZipFileZipEntrySource</code> is used to ensure that temp files are encrypted.
* </ul><p>
*/
+@SuppressWarnings({"java:S106","java:S4823","java:S1192"})
public final class LoadPasswordProtectedXlsxStreaming {
- private LoadPasswordProtectedXlsxStreaming() {
- }
+ private LoadPasswordProtectedXlsxStreaming() {}
public static void main(String[] args) throws Exception {
LoadPasswordProtectedXlsx.execute(args, LoadPasswordProtectedXlsxStreaming::printSheetCount);
* <li><code>SXSSFWorkbookWithCustomZipEntrySource</code> extends SXSSFWorkbook to ensure temp files are encrypted.
* </ul><p>
*/
-public class SavePasswordProtectedXlsx {
+@SuppressWarnings({"java:S106","java:S4823","java:S1192"})
+public final class SavePasswordProtectedXlsx {
+
+ private SavePasswordProtectedXlsx() {}
public static void main(String[] args) throws Exception {
if(args.length != 2) {
}
TempFileUtils.checkTempFiles();
}
-
+
public static void save(final InputStream inputStream, final String filename, final String pwd)
throws InvalidFormatException, IOException, GeneralSecurityException {
==================================================================== */
package org.apache.poi.xssf.usermodel.examples;
+import java.io.ByteArrayOutputStream;
+
import org.apache.poi.openxml4j.opc.OPCPackage;
import org.apache.poi.xssf.extractor.XSSFExportToXml;
-import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.apache.poi.xssf.usermodel.XSSFMap;
-
-import java.io.ByteArrayOutputStream;
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
/**
* Print all custom XML mappings registered in the given workbook
*/
-public class CustomXMLMapping {
+@SuppressWarnings({"java:S106","java:S4823","java:S1192"})
+public final class CustomXMLMapping {
+
+ private CustomXMLMapping() {}
public static void main(String[] args) throws Exception {
try (OPCPackage pkg = OPCPackage.open(args[0]);
/**
* Iterate over rows and cells
*/
-public class IterateCells {
+@SuppressWarnings({"java:S106","java:S4823","java:S1192"})
+public final class IterateCells {
+
+ private IterateCells() {}
public static void main(String[] args) throws IOException {
try (
* <li><code>AesZipFileZipEntrySource</code> is used to ensure that temp files are encrypted.
* </ul><p>
*/
+@SuppressWarnings({"java:S106","java:S4823","java:S1192"})
public final class LoadPasswordProtectedXlsx {
+ private LoadPasswordProtectedXlsx() {}
+
public interface EncryptionHandler {
void handle(final InputStream inputStream) throws Exception;
}
/**
* Demonstrates how to insert pictures in a SpreadsheetML document
*/
-public class WorkingWithPictures {
+@SuppressWarnings({"java:S106","java:S4823","java:S1192"})
+public final class WorkingWithPictures {
+ private WorkingWithPictures() {}
+
public static void main(String[] args) throws IOException {
//create a new workbook
/**
* Build a bar chart from a template docx
*/
+@SuppressWarnings({"java:S106","java:S4823","java:S1192"})
public final class BarChartExample {
private BarChartExample() {}
/**
* Build a chart without reading template file
*/
+@SuppressWarnings({"java:S106","java:S4823","java:S1192"})
public final class ChartFromScratch {
private ChartFromScratch() {}
/**
* Demonstrates how to add pictures in a .docx document
*/
+@SuppressWarnings({"java:S106","java:S4823","java:S1192"})
public final class SimpleImages {
private SimpleImages() {}
* embedded into a WordprocessingML document. Note that the test has currently
* only been conducted with a binary Excel workbook and NOT yet with a
* SpreadsheetML workbook embedded into the document.<p>
- *
+ *
* This code was successfully tested with the following file from the POI test collection:
* http://svn.apache.org/repos/asf/poi/trunk/test-data/document/EmbeddedDocument.docx
*/
+@SuppressWarnings({"java:S106","java:S4823","java:S1192"})
public class UpdateEmbeddedDoc {
private XWPFDocument doc;