Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get the workbook file name i.e. excel file name

I am working on an existing .xlsx file. Can any one share with me that, how can I get my current file name?

I mean, suppose I am working on test.xlsx file. How can I get the name of workbook "test.xlsx" using apache poi.

like image 674
Sankumarsingh Avatar asked Jul 18 '13 19:07

Sankumarsingh


People also ask

How do I find the workbook name in Excel?

Select a blank cell, type =GetBook() into the cell, then press the Enter key. You can see the workbook name is populated on the selected cell.

How do I extract file names?

To extract filename from the file, we use “GetFileName()” method of “Path” class. This method is used to get the file name and extension of the specified path string. The returned value is null if the file path is null. Syntax: public static string GetFileName (string path);

Where is the name of workbook displayed?

In the top center of the window to the right of the Quick Access toolbar is the Title bar. The Title Bar displays the title of your workbook.

What is the formula for file name in Excel?

Insert the current file name only Type or paste the following formula to insert the name of the current file in a cell: =MID(CELL("filename"),SEARCH("[",CELL("filename"))+1, SEARCH("]",CELL("filename"))-SEARCH("[",CELL("filename"))-1)


1 Answers

POI can open a workbook from any InputStream you care to throw at it. (Files are lower memory, but you can use a stream if you want, and many people do). If a stream isn't file backed, then it doesn't have a filename, so no amount of pleading with POI will get you one!

If you are opening a Workbook from a File, then that File object knows the filename. Ask that for it! Otherwise, if opening from an InputStream, there most likely isn't a filename, so there's nothing to supply.

Finally, be aware that unlike the name of a Sheet, which is stored in the file, the name of the file itself isn't something magic. Take test.xls, copy it to test2.xls, and also store it in a database blob field. Load all. All of them are the same file, but two of them have different filenames, and one has no filename at all!

like image 170
Gagravarr Avatar answered Sep 23 '22 05:09

Gagravarr