How to make a xls file a datasource for JasperReports? - url

I have a web page that returns a xls file.
I'm trying to use the output of the page as a datasource for JasperReports.
Right now I have something like
JRXlsDataSource ds = new JRXlsDataSource(JRLoader.getLocationInputStream("http://192.168.20.19/people/XLS.jsf"));
but I get this error
net.sf.jasperreports.engine.JRException: jxl.read.biff.BiffException: The input file was not found
How can I read the stream and then use it in the JasperPrint object?

Please refer the link below, it would provide a complete idea of XLS datasource for jasper report
http://jasperreports.sourceforge.net/sample.reference/xlsdatasource/index.html

Related

How to read a xml file which is not well_formed?

I am trying to read an XML file with xml.etree.ElementTree
it gives me an error when it reaches a specific line of the file. I was assuming that this is a regular XML file. please help me how can I resolve it?
xml_file =ET.parse("/Users/arash/project/my_project/extracting_features/TraceData.log").getroot()

How to avoid Excel "bad format error" when saving spreadsheet

Using PHPSpreadsheet saving XLSX format works OK running the default code
$writer = new \PhpOffice\PhpSpreadsheet\Writer\Xlsx($spreadsheet);
$writer->save("filename.xlsx");
But if I want to have the user to select the target directory using
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment;filename="filename.xlsx"');
header('Cache-Control: max-age=0');
$writer = IOFactory::createWriter($spreadSheet, 'Xlsx');
$writer->save('php://output');
The file saves OK but Excel 2016 does not want to open it. Excel returns the following error
Excel Error
I looked through all documentation and posts but cannot find the solution.
Thanks !
Edit: Just in case, this solution does not work for me.
Edit 2: The sample provided Simple Download Xlsx works perfectly, but when doing a copy/paste for my spreadsheet, Chrome gives me a
Resource interpreted as Document but transferred with MIME type application/octet-stream
Edit 3: Used
ob_end_flush(); to clean any left over header in my code.
The file now saves OK, but needs repair when opening in Excel. Why ?
Thanks
Solution:
Bug from PhpSpreadsheet.
When using
header("Content-Type: application/vnd.ms-excel");
i.e. compatibility mode for Excel, the file opens OK.

IOS Xamarin can't read XML File

So I've search everywhere. Xamarin Docs, goggle, here, W3.
All I need to do is store some small data in an XML file.
I created the XML, got the code lined up and when i go to build it.
IOS.....Can't find file.
I've googled the answer countless times, and they all say the same thing, Make sure it is set as Content or make sure it is "Embedded Resource" I've tried it both ways, It can't find the file to access it. Is IOS really that stupid? No issues in Android, took it 30 secs. Add it to the Assets and boom there it is.
But How to get IOS to Recognize xml file(find it)?
the code is this
XDocuent doc = new XDocument.Load("StoredLogs.xml") <that line is where it throws the error, through all the break points that it is.
After this it steps through a loop to bind the data in the xml to an object
Logs a.Id = x.Element("Id).Value......
a.name......... and so
All i want is basic offline storage.
iOS really that stupid?
Yes :P
When you add the XML file as an EmbeddedResource, you need to read it from the assembly instead of the path
For example:
var readme = typeof(NameSpace.App).GetTypeInfo().Assembly
.GetManifestResourceStrean("resourcename.xml");
using (var sr = new StreamReader(readme)) {
//Read the stream
}

Reading XML file using DXL(DOORS Scripting) and exporting to EXCEL dynamically

I need to read an XML file using DXL scripting and Exporting to EXCEl.
Is there any script in DXL already available?
Please help me out.
Thanks,
Sri
It can be done but there is no quick function built in to DXL to read XML, you have to build your own. Exporting to Excel is also possible by either going to Comma Separated Values or by using the OLE methods.
There is one library created by Mathias Mamtsch, using it you can create DOM from input string xml, then read,write attributes, values, iterate over attributes ,tags and so on.
http://sourceforge.net/projects/dxlstandardlib
In DXL world you have to write everything on you own.
It uses some helpers dxl files so to use it you have to use more than one additional dxl files.
For example one of the function there:
/*! \memberof XMLDocument
\return true - if the XML document could be loaded and parsed correctly. 'false' if there was an error loading the document.
\param xd The XMLDocument into which the contents shall be loaded.
\param s the contents of the XML document to load
\brief This function loads the XML content of a string into an XMLDocument object.
*/
bool loadXML (XMLDocument xd, string s) {
bool result = false
checkOLE ( oleMethod (getOleHandle_ xd, "LoadXML", oleArgs <- s, result) )
return result
}
These functions use OLE objects so I think they are Windows specific and under Linux the code will not work. But not sure.

Open XML SDK: opening a Word template and saving to a different file-name

This one very simple thing I can't find the right technique. What I want is to open a .dotx template, make some changes and save as the same name but .docx extension. I can save a WordprocessingDocument but only to the place it's loaded from. I've tried manually constructing a new document using the WordprocessingDocument with changes made but nothing's worked so far, I tried MainDocumentPart.Document.WriteTo(XmlWriter.Create(targetPath)); and just got an empty file.
What's the right way here? Is a .dotx file special at all or just another document as far as the SDK is concerned - should i simply copy the template to the destination and then open that and make changes, and save? I did have some concerns if my app is called from two clients at once, if it can open the same .dotx file twice... in this case creating a copy would be sensible anyway... but for my own curiosity I still want to know how to do "Save As".
I would suggest just using File.IO to copy the dotx file to a docx file and make your changes there, if that works for your situation. There's also a ChangeDocumentType function you'll have to call to prevent an error in the new docx file.
File.Copy(#"\path\to\template.dotx", #"\path\to\template.docx");
using(WordprocessingDocument newdoc = WordprocessingDocument.Open(#"\path\to\template.docx", true))
{
newdoc.ChangeDocumentType(WordprocessingDocumentType.Document);
//manipulate document....
}
While M_R_H's answer is correct, there is a faster, less IO-intensive method:
Read the template or document into a MemoryStream.
Within a using statement:
open the template or document on the MemoryStream.
If you opened a template (.dotx) and you want to store it as a document (.docx), you must change the document type to WordprocessingDocumentType.Document. Otherwise, Word will complain when you try to open the document.
Manipulate your document.
Write the contents of the MemoryStream to a file.
For the first step, we can use the following method, which reads a file into a MemoryStream:
public static MemoryStream ReadAllBytesToMemoryStream(string path)
{
byte[] buffer = File.ReadAllBytes(path);
var destStream = new MemoryStream(buffer.Length);
destStream.Write(buffer, 0, buffer.Length);
destStream.Seek(0, SeekOrigin.Begin);
return destStream;
}
Then, we can use that in the following way (replicating as much of M_R_H's code as possible):
// Step #1 (note the using declaration)
using MemoryStream stream = ReadAllBytesToMemoryStream(#"\path\to\template.dotx");
// Step #2
using (WordprocessingDocument newdoc = WordprocessingDocument.Open(stream, true)
{
// You must do the following to turn a template into a document.
newdoc.ChangeDocumentType(WordprocessingDocumentType.Document);
// Manipulate document (completely in memory now) ...
}
// Step #3
File.WriteAllBytes(#"\path\to\template.docx", stream.GetBuffer());
See this post for a comparison of methods for cloning (or duplicating) Word documents or templates.

Resources