Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to remove objects from Excel by JAVA

Shulou Source: shulou.com Published: 2022-06-01 20:36:53 10月03日 Update

This article mainly explains "how JAVA removes the objects in Excel". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "how to remove objects from Excel by JAVA".

To determine whether there is an object.

Post the code you tried today first. After the code is executed, the file becomes smaller, but the objects in the file still exist. So there's nothing I can do about it. Stupid office.

/ / JAVA Import Excel error java.io.IOException: Zip bomb detected! ZipSecureFile.setMinInflateRatio (- 1.0d); / / create the workbook XSSFWorkbook book of XSSF = XSSFWorkbookFactory.createWorkbook (file.getInputStream ()); / / this line is useless, just to see the method and value CTWorksheet ctWorksheet = book.getSheetAt (0). GetCTWorksheet (); / / get the drawing manager XSSFDrawing drawingPatriarch = book.getSheetAt (0). GetDrawingPatriarch () / / this line is useless, because the object still exists book.getSheetAt (0). GetPackagePart (). Clear (); / nothing uses CTShape ctShape = new CTShapeImpl (ctWorksheet.schemaType ()); / / gets the XSSFShape list, which is the damn object. List shapes = drawingPatriarch.getShapes (); / / a, b, c, d, flag, shapeNames are useless, just to observe the quantity and object name int a = 0; int b = 0; int c = 0; int d = 0; boolean flag = false; List shapeNames = new ArrayList () when the code is executed For (XSSFShape xssfShape:shapes) {shapeNames.add (xssfShape.getShapeName ()); xssfShape.setLineStyle (0); xssfShape.setLineWidth (0); / / get the object's BWH to 0. XSSFClientAnchor anchor = (XSSFClientAnchor) xssfShape.getAnchor (); anchor.setCol1 (0); anchor.setCol2 (0); anchor.setDx1 (0); anchor.setDx2 (0); anchor.setDy1 (0); anchor.setDy2 (0); anchor.setRow1 (0); anchor.setRow2 (1) } System.out.println ("a:" + a); System.out.println ("b:" + b); System.out.println ("c:" + c); System.out.println ("d:" + d); System.out.println ("flag:" + flag); System.out.println ("object name:" + shapeNames.get (0))

After transformation

XSSFWorkbook book = XSSFWorkbookFactory.createWorkbook (file.getInputStream ()); XSSFDrawing drawingPatriarch = book.getSheetAt (0). GetDrawingPatriarch (); if (drawingPatriarch! = null & & drawingPatriarch.getShapes (). Size () > 0) {return ApiResult.error ("there are hidden objects in the file, please reorganize. Paste, only paste text ");} at this point, I believe you have a deeper understanding of" JAVA how to remove the objects in Excel ", you might as well to actually operate it! Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Tags: Object nothing code file one line content just name method learning practical deeper BWH interest method practicality practicality that is simple operation quantity Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Huawei NVidia OPPO Reno Docker Shulou Tech Info