I am trying to create an XML spreadsheet for use with Excel. I first saved a
simple spreadsheet as an XML file, and now I am trying to recreate that file
in code, using .NET 2.0. The beginning of the XML file should look like the
following:
<?xml version="1.0"?>
<?mso-application progid="Excel.Sheet"?>
<Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet"
xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:x="urn:schemas-microsoft-com:office:excel"
xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"
xmlns:html="http://www.w3.org/TR/REC-html40">
I can create all of this except for the first xmlns attribute in the
Workbook element. Here is my code:
writer.WriteStartDocument();
writer.WriteWhitespace("\n");
writer.WriteRaw("<?mso-application progid=\"Excel.Sheet\"?>");
writer.WriteWhitespace("\n");
Writer.WriteStartElement("Workbook");
writer.WriteAttributeString("xmlns",
"urn:schemas-microsoft-com:office:spreadsheet");
writer.WriteAttributeString("xmlns", "o", null,
"urn:schemas-microsoft-com:office:office");
writer.WriteAttributeString("xmlns", "x", null,
"urn:schemas-microsoft-com:office:excel");
writer.WriteAttributeString("xmlns", "ss", null,
"urn:schemas-microsoft-com:office:spreadsheet");
writer.WriteAttributeString("xmlns", "html", null,
"http://www.w3.org/TR/REC-html40");
writer.WriteEndElement();
When the code gets to the first WriteAttributeString statement, it gives an
error "The prefix '' cannot be redefined to
'urn:schemas-microsoft-com:office:spreadsheet' within the same start element
tag." If I comment out that line, it works fine, minus the first attribute,
or course. I have tried every permutation I can think of for every oveload to
write an xmlns attribute withoug a local name, to no avail.
Any suggestions?
Thanks.
Dan 3 11150
dhurwitz wrote:
<?mso-application progid="Excel.Sheet"?>
<Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet"
writer.WriteRaw("<?mso-application progid=\"Excel.Sheet\"?>");
That is a processing instruction so no need to force something with
WriteRaw, doing
writer.WriteProcessingInstruction("mso-application",
"progid=\"Excel.Sheet\"");
should suffice.
Writer.WriteStartElement("Workbook");
writer.WriteAttributeString("xmlns",
"urn:schemas-microsoft-com:office:spreadsheet");
Write the element in the proper namespace, there is no need to
explicitly write an xmlns declaration, doing
writer.WriteStartElement("Workbook",
"urn:schemas-microsoft-com:office:spreadsheet");
suffices to have the writer add the xmlns declaration automatically.
--
Martin Honnen --- MVP XML http://JavaScript.FAQTs.com/
Thank you. That is very helpful.
--Dan
"Martin Honnen" wrote:
>
dhurwitz wrote:
<?mso-application progid="Excel.Sheet"?>
<Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet"
writer.WriteRaw("<?mso-application progid=\"Excel.Sheet\"?>");
That is a processing instruction so no need to force something with
WriteRaw, doing
writer.WriteProcessingInstruction("mso-application",
"progid=\"Excel.Sheet\"");
should suffice.
Writer.WriteStartElement("Workbook");
writer.WriteAttributeString("xmlns",
"urn:schemas-microsoft-com:office:spreadsheet");
Write the element in the proper namespace, there is no need to
explicitly write an xmlns declaration, doing
writer.WriteStartElement("Workbook",
"urn:schemas-microsoft-com:office:spreadsheet");
suffices to have the writer add the xmlns declaration automatically.
--
Martin Honnen --- MVP XML http://JavaScript.FAQTs.com/
"dhurwitz" <dh******@discussions.microsoft.comwrote in message
news:E8**********************************@microsof t.com...
Also I find it better to use the indent property of the writer, rather than
writing loads of whilespace newlines manually.
Thank you. That is very helpful.
--Dan
"Martin Honnen" wrote:
>>
dhurwitz wrote:
<?mso-application progid="Excel.Sheet"?>
<Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet"
writer.WriteRaw("<?mso-application progid=\"Excel.Sheet\"?>");
That is a processing instruction so no need to force something with WriteRaw, doing writer.WriteProcessingInstruction("mso-application", "progid=\"Excel.Sheet\""); should suffice.
Writer.WriteStartElement("Workbook");
writer.WriteAttributeString("xmlns",
"urn:schemas-microsoft-com:office:spreadsheet");
Write the element in the proper namespace, there is no need to explicitly write an xmlns declaration, doing writer.WriteStartElement("Workbook", "urn:schemas-microsoft-com:office:spreadsheet"); suffices to have the writer add the xmlns declaration automatically.
--
Martin Honnen --- MVP XML http://JavaScript.FAQTs.com/ This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: JemPower |
last post by:
Hi,
I've created a routine that reads from my sql server and outputs the
contents to an XML file.
I have two problems.
Firstly, if an error occurs (i.e. the user doesn't supply the correct...
|
by: vikas |
last post by:
Hi
I want to create following xml document using xmlwriter
<?xml version="1.0" ?>
- <epps>
- <remit_trn type="technical">
<remit_date_dtm dtm = "201" >test</remit_date_dtm>...
|
by: Abdessamad Belangour |
last post by:
Hi all,
I have developped an application that generate XML documents.
At most time it works fine, but sometimes (when the size of data to export
is big) i got the error message :
<< The...
|
by: Mori |
last post by:
I am using the following code to manufactue xml using xmltextwriter. The xml
is okay except for the extra set of start document and the outer <string>
element. Where do they come from and how do...
|
by: Marc Gravell |
last post by:
I want to write a method that will accept a stream as a parameter, and which
will write xml to the stream (based in reality on database results) using
the XmlTextWriter class. However, this insists...
|
by: Paul Hadfield |
last post by:
Hi,
Wonder if anyone can help me on this, In DotNet2.0 I've been quite happily
using the WriteAttributeString method of XmlWriter object, but have run into
a problem when trying to output a...
|
by: remya1000 |
last post by:
i'm using VB.NET and Microsoft Access.
and in one of my Access table is called Emp.mdb. and in that Emp.mdb i have lots of tables like MD1, MD2,......MD58 and MB1,MB2,......MB67 and some other...
|
by: G.S. |
last post by:
Is it acceptable to use { } blocks to improve readability and
maintainability of the code?
Example:
//add the checkbox column
DataGridViewCheckBoxColumn column = new...
|
by: DolphinDB |
last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation.
Take...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
| |