Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to remove objects from Excel by JAVA

2025-04-07 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

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!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report