I am exporting some data from my database in xml format.
The file exported has an extension as .xml and it is viewed as Excel file.
I want to insert an image in this xml file so that when we view it as Excel we will be able to see the image along with the data.
Whatever I have found from the internet is that there is no straight forward way to insert an image in xml file as xml file were designed for handling the data.
Can any one tell me what is the approach I will have to follow in order to obtain the desired functionality.
xml files are text files, and you can embedd binary data if you encode it with Base64 algorithm.
But to view the image you will need to decode the Base64-string and pass the result binary data to an image viewer implementation.
It cannot be done in MS Excel. You will need to implement your own viewer.
You won't be able to view an image inside of an XML file unless you write a dedicated application for it that knows about your particular requirement.
The reason is that XML is character-based, but images are not - they are binary data. A way to embed your image nevertheless is to transform it to something character-based first. For example, you could Base64-encode your image first and embed the resulting string in your XML. But I suppose there is no way to tell Excel to interpret this data as an image right away.
Because embedding binary files into XML using Base64 is such a common idiom, XML Schema even has its own data type for this: base64Binary.
Related
At work, we're modifying an XLSX file, and we would like to turn this modified file into an HTML file (to convert it into PDF using Puppeteer#, but it's not the point here).
We know how to get XML files of this XLSX, and I already found XSLCompiledTransform to convert XML files to HTML.
The annoyance here is that, from what I have read for XSLCompiledTransform, to transform XML file to HTML you need one stylesheet + one XML file.
This brings three problems :
It looks like the stylesheet into XLSX for each sheet isn't well formated to use with this XSLCompiledTransform.
The XLSX file contains multiples sheets, so we would have to fuse them in some manner, and we don't know how.
It is not just some random XML files, they're parts of an XLSX file. Thus there are also some XML files in addition to the sheets (like a workbook and other files) and we can't figure how we could generate an HTML file which is precisely like the XLSX file as open using Excel without using these XML files.
These problems could be resumed as: We struggle to find how to generate an HTML file which will look exactly like the original whole XLSX file.
We don't really want to create an HTML file from some XML files, so any means to transform an XLSX to HTML is good.
We also know that there are some tools and libs available to directly do this, but all the ones I've found aren't free, and we would like to avoid to pay for that as it's the first time we need it and maybe the last.
Does anyone know an accurate option to programmatically transform an XLSX file to HTML, keeping every style options and using C#?
I have to big files of MS Word & PDF which contains images, text fields, tables.
I need to insert text into these files dynamically at specific locations. I've tried Bookmarks method in Word but I can't use that method now. I've extracted data into byte array and tried to write in pdf but file gets corrupted. Here is the code:
byte[] bytes = System.IO.File.ReadAllBytes("CDC.doc");
FileStream fs = new FileStream("CDC.pdf", FileMode.OpenOrCreate);
fs.Write(bytes, 0, bytes.Length);
fs.Close();
Is there any way that I can convert these pdf/ word files to get PDF code for these files and then I can append data to specific locations in that code. Please advise. Thanks!
If I understand you right, you would like to develop a code that would replace all placeholders in a Word document acting as a template with your application data. For placeholders you can use Bookmarks, but a better choice would be Content Controls. You can use Open XML SDK to parse such a template Word document and replace Content Controls with data. This approach uses a free MS library but is tedious.
A much easier approach would be using a ready-made library which can work with templates, which contain placeholders that will get replaced with your real app data at runtime. In your C# application you can prepare the data (as C# data objects or XML) and merge this data with the template. Output can be in docx, pdf or xps format. You can check out some of the examples here.
I'm currently working with the new German ZUGFeRD files. These are PDF A/3 files who have an embedded XML file in them which contains data.
I want to extract this XML file from the PDF A/3 using abcpdf 8.1 with C#.
Any idea how to do this ?
Thanks a lot and regards,
I don't know abcpdf but I guess that the pdf libs offer similar access to the pdfs content.
First take a look at Das-ZUGFeRD-Format_1p0.pdf. Especially page 112. The images shows the object tree you have to traverse in order to find the xml stream.
With this tree you have the names, the types and the direction. Now you can traverse the pdf object tree to get to the XML content that you are looking for.
The steps based on the diagram.
Read your PDF
Get the catalog inside your PDF
Get the Array with name AF from Catalog
Get first element from AF array (should be file spec)
From file spec get the dictionary named EF
Get the stream content of EF
This are the steps you need to perform in order to get to the content.
To display the structure of a pdf and browse the tree I would recommend to use a tool like iText RUPS
What did i do with abcpdf:
Get the Objectsoup Array from the Doc (Pretty much an array of all Objects in the Doc)
as ZUGFeRD allows only one embedded file inside the PDF, i just searched this objectsoup-array for the one of the type StreamObject that contains /EmbeddedFile
Decompress the Stream of that object, get the byte[] of the stream and write it into an xml file
Which is Excel's preferred format for receiving data from the clipboard? The data is in a C# / .NET application.
I had been saving to the clipboard in CSV format, but now I want to start giving Excel formatting information (eg. make some cells bold). CSV format is no longer enough.
When I copy from Excel, the clipboard holds 24 formats!
System.Windows.Clipboard.GetDataObject().GetFormats().Dump();
EnhancedMetafile
System.Drawing.Imaging.Metafile
MetaFilePict
Bitmap
System.Drawing.Bitmap
System.Windows.Media.Imaging.BitmapSource
Biff12
Biff8
Biff5
SymbolicLink
DataInterchangeFormat
XML Spreadsheet
HTML Format
Text
UnicodeText
System.String
CSV
Rich Text Format
Embed Source
Object Descriptor
Link Source
Link Source Descriptor
Link
Format129
*
I believe what you're seeing is that Excel prepares the data when you copy to the clipboard in many different formats depending on where you end up pasting it. You probably need to look into the Office XML format for Excel.
See this example xml at Wikipedia for a better idea of the format. While I've never used it before, I'm pretty sure Excel would simply let you paste in the XML directly (if it's the right schema).
I am developing a note taking app, in which user will record the audio and will do some text inputting. At the end I will have one .txt file and another .mp3 file. Now I want to merge this two files in one single file. Further I will also need to separate both the file when user open that single file. So what should I do ? Should I use XML serialization as there is no binary serialization in WinRT ?
Unless I'm missing something in your question, some options include:
Use a zip file (or some other container)
Encode the mp3 in Base 64 and send it as a string (XML would work well here)
Put the text in one of the mp3 header tags
Create a new file format which includes both mp3 data and text data
Use multi-part MIME, like an email does when sending attachments