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.
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.
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);
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.
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)
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!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With