@@ -29,17 +29,13 @@ public class SheetUtility {
2929 * @throws OpenWorkbookException If an error occurred while opening the workbook
3030 */
3131 public static Integer length (File file ) throws ExtensionNotValidException , IOException , OpenWorkbookException {
32- /* Check extension */
33- String extension = ExcelUtility .checkExcelExtension (file .getName ());
34-
3532 /* Open file excel */
36- FileInputStream fileInputStream = new FileInputStream (file );
37- Workbook workbook = WorkbookUtility .open (fileInputStream , extension );
33+ Workbook workbook = WorkbookUtility .open (file );
3834
3935 Integer totalSheets = workbook .getNumberOfSheets ();
4036
4137 /* Close file */
42- WorkbookUtility .close (workbook , fileInputStream );
38+ WorkbookUtility .close (workbook );
4339
4440 return totalSheets ;
4541 }
@@ -53,12 +49,8 @@ public static Integer length(File file) throws ExtensionNotValidException, IOExc
5349 * @throws OpenWorkbookException If an error occurred while opening the workbook
5450 */
5551 public static List <String > getNames (File file ) throws ExtensionNotValidException , IOException , OpenWorkbookException {
56- /* Check extension */
57- String extension = ExcelUtility .checkExcelExtension (file .getName ());
58-
5952 /* Open file excel */
60- FileInputStream fileInputStream = new FileInputStream (file );
61- Workbook workbook = WorkbookUtility .open (fileInputStream , extension );
53+ Workbook workbook = WorkbookUtility .open (file );
6254
6355 /* Iterate all the sheets */
6456 Iterator <Sheet > sheetIterator = workbook .iterator ();
@@ -69,7 +61,7 @@ public static List<String> getNames(File file) throws ExtensionNotValidException
6961 }
7062
7163 /* Close file */
72- WorkbookUtility .close (workbook , fileInputStream );
64+ WorkbookUtility .close (workbook );
7365
7466 return sheetNames ;
7567 }
@@ -85,17 +77,13 @@ public static List<String> getNames(File file) throws ExtensionNotValidException
8577 * @throws SheetNotFoundException If the sheet to open is not found
8678 */
8779 public static Integer getIndex (File file , String sheetName ) throws ExtensionNotValidException , IOException , OpenWorkbookException , SheetNotFoundException {
88- /* Check extension */
89- String extension = ExcelUtility .checkExcelExtension (file .getName ());
90-
9180 /* Open file excel */
92- FileInputStream fileInputStream = new FileInputStream (file );
93- Workbook workbook = WorkbookUtility .open (fileInputStream , extension );
81+ Workbook workbook = WorkbookUtility .open (file );
9482
9583 int sheetIndex = workbook .getSheetIndex (sheetName );
9684
9785 /* Close file */
98- WorkbookUtility .close (workbook , fileInputStream );
86+ WorkbookUtility .close (workbook );
9987
10088 if (sheetIndex < 0 ) {
10189 throw new SheetNotFoundException ("No sheet was found" );
@@ -114,12 +102,8 @@ public static Integer getIndex(File file, String sheetName) throws ExtensionNotV
114102 * @throws SheetNotFoundException If the sheet to open is not found
115103 */
116104 public static String getName (File file , Integer position ) throws ExtensionNotValidException , IOException , OpenWorkbookException , SheetNotFoundException {
117- /* Check extension */
118- String extension = ExcelUtility .checkExcelExtension (file .getName ());
119-
120105 /* Open file excel */
121- FileInputStream fileInputStream = new FileInputStream (file );
122- Workbook workbook = WorkbookUtility .open (fileInputStream , extension );
106+ Workbook workbook = WorkbookUtility .open (file );
123107
124108 String sheetName ;
125109 try {
@@ -129,7 +113,7 @@ public static String getName(File file, Integer position) throws ExtensionNotVal
129113 }
130114
131115 /* Close file */
132- WorkbookUtility .close (workbook , fileInputStream );
116+ WorkbookUtility .close (workbook );
133117
134118 return sheetName ;
135119 }
@@ -187,7 +171,7 @@ public static Sheet create(Workbook workbook, String sheetName) {
187171 }
188172
189173 /**
190- * Opens the sheet of the Excel file<p>
174+ * Gets the sheet of the Excel file<p>
191175 * If not specified, the first sheet will be opened
192176 * @param file Excel file
193177 * @return The sheet in the workbook
@@ -196,12 +180,12 @@ public static Sheet create(Workbook workbook, String sheetName) {
196180 * @throws OpenWorkbookException If an error occurred while opening the workbook
197181 * @throws SheetNotFoundException If the sheet to open is not found
198182 */
199- public static Sheet open (File file ) throws ExtensionNotValidException , IOException , OpenWorkbookException , SheetNotFoundException {
200- return open (file , 0 );
183+ public static Sheet get (File file ) throws ExtensionNotValidException , IOException , OpenWorkbookException , SheetNotFoundException {
184+ return get (file , 0 );
201185 }
202186
203187 /**
204- * Opens the sheet of the Excel file
188+ * Gets the sheet of the Excel file
205189 * @param file Excel file
206190 * @param sheetName The sheet name in the workbook
207191 * @return The sheet in the workbook
@@ -210,27 +194,23 @@ public static Sheet open(File file) throws ExtensionNotValidException, IOExcepti
210194 * @throws OpenWorkbookException If an error occurred while opening the workbook
211195 * @throws SheetNotFoundException If the sheet to open is not found
212196 */
213- public static Sheet open (File file , String sheetName ) throws ExtensionNotValidException , IOException , OpenWorkbookException , SheetNotFoundException {
214- /* Check extension */
215- String extension = ExcelUtility .checkExcelExtension (file .getName ());
216-
197+ public static Sheet get (File file , String sheetName ) throws ExtensionNotValidException , IOException , OpenWorkbookException , SheetNotFoundException {
217198 /* Open file excel */
218- FileInputStream fileInputStream = new FileInputStream (file );
219- Workbook workbook = WorkbookUtility .open (fileInputStream , extension );
199+ Workbook workbook = WorkbookUtility .open (file );
220200
221201 /* Open sheet */
222202 Sheet sheet = workbook .getSheet (sheetName );
223203 if (sheet == null )
224204 throw new SheetNotFoundException ();
225205
226206 /* Close workbook */
227- WorkbookUtility .close (workbook , fileInputStream );
207+ WorkbookUtility .close (workbook );
228208
229209 return sheet ;
230210 }
231211
232212 /**
233- * Opens the sheet of the Excel file
213+ * Gets the sheet of the Excel file
234214 * @param file Excel file
235215 * @param position The index in the workbook
236216 * @return The sheet in the workbook
@@ -239,44 +219,40 @@ public static Sheet open(File file, String sheetName) throws ExtensionNotValidEx
239219 * @throws OpenWorkbookException If an error occurred while opening the workbook
240220 * @throws SheetNotFoundException If the sheet to open is not found
241221 */
242- public static Sheet open (File file , Integer position ) throws ExtensionNotValidException , IOException , OpenWorkbookException , SheetNotFoundException {
243- /* Check extension */
244- String extension = ExcelUtility .checkExcelExtension (file .getName ());
245-
222+ public static Sheet get (File file , Integer position ) throws ExtensionNotValidException , IOException , OpenWorkbookException , SheetNotFoundException {
246223 /* Open file excel */
247- FileInputStream fileInputStream = new FileInputStream (file );
248- Workbook workbook = WorkbookUtility .open (fileInputStream , extension );
224+ Workbook workbook = WorkbookUtility .open (file );
249225
250226 /* Open sheet */
251227 Sheet sheet = workbook .getSheetAt (position );
252228 if (sheet == null )
253229 throw new SheetNotFoundException ();
254230
255231 /* Close workbook */
256- WorkbookUtility .close (workbook , fileInputStream );
232+ WorkbookUtility .close (workbook );
257233
258234 return sheet ;
259235 }
260236
261237 /**
262- * Opens the sheet in the workbook.<p>
238+ * Gets the sheet in the workbook.<p>
263239 * If not specified, the first sheet will be opened
264240 * @param workbook The {@code Workbook} where there is the sheet
265241 * @return The sheet in the workbook in first position
266242 * @throws SheetNotFoundException If the sheet to open is not found
267243 */
268- public static Sheet open (Workbook workbook ) throws SheetNotFoundException {
269- return open (workbook , 0 );
244+ public static Sheet get (Workbook workbook ) throws SheetNotFoundException {
245+ return get (workbook , 0 );
270246 }
271247
272248 /**
273- * Opens the sheet in the workbook.
249+ * Gets the sheet in the workbook.
274250 * @param workbook The {@code Workbook} where there is the sheet
275251 * @param sheetName The sheet name in the workbook
276252 * @return The sheet in the workbook
277253 * @throws SheetNotFoundException If the sheet to open is not found
278254 */
279- public static Sheet open (Workbook workbook , String sheetName ) throws SheetNotFoundException {
255+ public static Sheet get (Workbook workbook , String sheetName ) throws SheetNotFoundException {
280256 /* Open sheet */
281257 Sheet sheet = workbook .getSheet (sheetName );
282258 if (sheet == null )
@@ -285,13 +261,13 @@ public static Sheet open(Workbook workbook, String sheetName) throws SheetNotFou
285261 }
286262
287263 /**
288- * Opens the sheet in the workbook.
264+ * Gets the sheet in the workbook.
289265 * @param workbook The {@code Workbook} where there is the sheet
290266 * @param position The index in the workbook
291267 * @return The sheet in the workbook
292268 * @throws SheetNotFoundException If the sheet to open is not found
293269 */
294- public static Sheet open (Workbook workbook , Integer position ) throws SheetNotFoundException {
270+ public static Sheet get (Workbook workbook , Integer position ) throws SheetNotFoundException {
295271 /* Open sheet */
296272 Sheet sheet = workbook .getSheetAt (position );
297273 if (sheet == null )
@@ -300,12 +276,12 @@ public static Sheet open(Workbook workbook, Integer position) throws SheetNotFou
300276 }
301277
302278 /**
303- * Opens the sheet in the workbook. If it doesn't find it, it creates it.
279+ * Gets the sheet in the workbook. If it doesn't find it, it creates it.
304280 * @param workbook The {@code Workbook} where there is the sheet
305281 * @param sheetName The sheet name in the workbook
306282 * @return The sheet in the workbook or a new one
307283 */
308- public static Sheet openOrCreate (Workbook workbook , String sheetName ) {
284+ public static Sheet getOrCreate (Workbook workbook , String sheetName ) {
309285 /* Open sheet */
310286 Sheet sheet = workbook .getSheet (sheetName );
311287 return sheet == null ? workbook .createSheet (sheetName ) : sheet ;
0 commit comments