I'm using the apache poi library (poi-3.8-20120326.jar)
How can I add the filename in the footer of an xls (hssf) document?
My approach is the following:
final static public String FILE_NAME = "&[File]";
public static void insertFilename(Sheet sheet) {
sheet.getFooter().setLeft(FILE_NAME);
}
The Problem is, the Microsoft Excel 2003 displays
File]
If I open the Footer-editor, click in the field, change nothing, and save--it works.
Editor shows it as
&[File]
Is there a workaround or a dirty trick to avoid this?
Thank you
It may look like "&[File]" in Excel, but that's not how it's stored internally. You're using HSSF for your .xls file, so use the following static HeaderFooter method to get the internal Excel code for the filename:
import org.apache.poi.hssf.usermodel.HeaderFooter;
String fileIndicator = HeaderFooter.file();
A quick look at the source code determines that the internal code is the string "&F".
If someone is using XSSF for a .xlsx file, then there is no corresponding file method. However, the documentation for XSSFHeaderFooter indicates that you can use the string "&F" directly.
Related
I have created a button to export the form data to simple Excel.
Everything is working file, even if i try to save this excel file in the file cabinet it gets saved correctly.
But when i try to downlaod the excel file, downloads wierd single cell file with special characters or system gives either an error or saves an empty excel file.
Can anyone help me in how to download the excel file from button click. I think i have issue in my responce.
My Code example is as follows:
.
.
.
xmlString += '</Table></Worksheet></Workbook>';// this is my xml string
var xlsFile = nlapiCreateFile('test.xls', 'EXCEL', nlapiEncrypt(xmlString, 'base64'));
response.writeFile(xmlFile);
}
error screenshot:
I think the reason for the response issue is because you are calling a non-existent variable "xmlFile" in writeFile();
try using this writeFile(xlsFile);
how could i transform the file to pdf
i already tried change extension name but the image will disappear and excel format will shift
so is there any good idea can transform the file and at the same time could save the image and format?
here is my export code
my maatwebsite package does not have the create method.
public function export(Order $order)
{
return Excel::download(new OrderExport($order), $order->no.'.xlsx');
}
and the excel file will look like
excel file
if i transform it will be likeenter image description here
We had a similar problem but with word files.
We came to the conclusion that using the lowriter from LibreOffice will do the trick.
Option 1
In addition we used the use TitasGailius\Terminal\Terminal; library for easy Terminal use.
$export_path is the path where your excel file is
$file is the name of your file
$resp = Terminal::in($export_path)->run('lowriter --headless --convert-to pdf '.$file);
Option 2
Using some built in functionality of the Excel package.
Excel::create('Filename', function($excel) {
})->export('xls');
https://docs.laravel-excel.com/2.1/export/export.html
I need to export some data from a few tables to a excel file. The thing is, the only working extension is '.xls', which is too old. So when I open this file it shows in protected exibition mode, even if I uncheck all boxes in Excel Protected Exibition Mode Options.
I'm not sure why I can't save in other extensions, like .xlsx, because if I use the native function to save as .xlsx: STR_OOXML_EXCEL_EXTENSION or just write .xlsx it saves, but does not open the document.
Shows this message: Excel cannot open the file 'file.xlsx' bacause the format or extension is not valid. Check if the document is corrupted or the extension matches the file format.
This is the code I'm using to create the file:
MyWorkbook := TsWorkbook.Create;
try
MyWorksheet := MyWorkbook.AddWorksheet('Orçamento');
And this is the one I'm using to save:
MyWorkbook.WriteToFile(MyDir + orcamento + '.xls', OUTPUT_FORMAT, True);
finally
MyWorkbook.Free;
The only option I can think of, is using another package, Excel or OpenOffice could help.
Settings: Lazarus 1.4.2 with FPC 2.6.4 and fpSpreadsheet 1.6.0, running on Windows 7 64-bit.
I'm not sure what your variable or constant OUTPUT_FORMAT contains but if you specify a format it should be one of these:
sfExcel2, sfExcel5, sfExcel8, sfOOXML, sfOpenDocument,
sfCSV, sfHTML, sfWikiTable_Pipes, sfWikiTable_WikiMedia
So if you want to save as .xlsx you could do this (use sfOOXML as format):
uses fpspreadsheet, fpstypes, xlsxooxml;
//...
MyWorkbook.WriteToFile(MyDir + orcamento + '.xlsx', sfOOXML, True);
You could also do this:
uses fpspreadsheet, fpstypes, xlsxooxml;
//...
MyWorkbook.WriteToFile(MyDir + orcamento + '.xlsx', True);
It will automatically detect the .xlsx extension and save the proper format.
You do need to include xlsxooxml in your uses clause because that unit registers the xlsx-format (automatically).
I create an Excel file (.xlsx) using the Aspose.Cells library. But I'm not able to read the data (retrieve rows) using OleDb commands after that, until I open the file and save it manually. I'm running something as simple as this one:
new OleDbDataAdapter("select * from [Sheet1$]", conn); // etc...
Saving the file increases the size of the file as well. Please note that this happens only with the .xlsx format, for the old .xls everything works fine. I even tried the demo code that they have on their website, but the result is the same. Am I missing something?
It seems you need to set the ExportCellName name property to true before saving to xlsx/xlsm format.
Please see the following sample.
//Create your workbook
Workbook workbook = new Workbook(filePath);
//Do your processing
//Save your workbook with export cell as true
OoxmlSaveOptions opts = new OoxmlSaveOptions();
opts.ExportCellName = true;
workbook.Save("output.xlsx", opts);
Note: I am working as Developer Evangelist at Aspose
I have the following code to open Excel template file and save it as .xlsx file and I get the error below when I try to open the new file. Please help to resolve this.
Excel cannot open the file ‘sa123.xlsx’ because the file format or the extension is not valid. Verify that the file has not been corrupted and that the file extension matches the format of the file.
string templateName = "C:\\temp\\sa123.xltx";
byte[] docAsArray = File.ReadAllBytes(templateName);
using (MemoryStream stream = new MemoryStream())
{
stream.Write(docAsArray, 0, docAsArray.Length); // THIS performs doc copy
File.WriteAllBytes("C:\\temp\\sa123.xlsx", stream.ToArray());
}
In order to do this you will need to use the Open XML SDK 2.0. Below is a snippet of code that worked for me when I tried it:
byte[] byteArray = File.ReadAllBytes("C:\\temp\\sa123.xltx");
using (MemoryStream stream = new MemoryStream())
{
stream.Write(byteArray, 0, (int)byteArray.Length);
using (SpreadsheetDocument spreadsheetDoc = SpreadsheetDocument.Open(stream, true))
{
// Change from template type to workbook type
spreadsheetDoc.ChangeDocumentType(SpreadsheetDocumentType.Workbook);
}
File.WriteAllBytes("C:\\temp\\sa123.xlsx", stream.ToArray());
}
What this code does is it takes your template file and opens it into a SpreadsheetDocument object. The type of this object is Template, but since you want it as a Workbook you call the ChangeDocumentType method to change it from a Template to a Workbook. This will work since the underlying XML is the same between a .xltx and a .xlsx file and it was just the type that was causing you an issue.
Excel sees the .xlsx extension and tries to open it as a worksheet file. But it isn't. It's a template file. When you have a template open in Excel and save it as a .xlsx file, it converts it to the worksheet format. What you are doing is the same as changing the extension in the filename. Try it in Windows Explorer and you will get the same result.
I believe you should be able to accomplish what you want by using the Excel Object Model. I have not used this though.