473,394 Members | 1,759 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

how to write this out using xmlwriter

Hi I have a .net application and am using the xml writer class to create an
xml file that opens as an excel file. I am trying to write out the following
but am having difficulty.
<Row>
<Cell ss:StyleID="s87">
<ss:Data ss: Type = "String">
<Font html:Color="#FF0000">M90</Font>
<Font>/Thu</Font>
</ss:Data>
</Cell>
This produces a cell with text with part of the text being red the M90 and
the other part being black.
I also have the following strings set up in my code
string spreadsheetNamespace = "urn:schemas-microsoft-com:office:spreadsheet";
string officeNamespace = "urn:schemas-microsoft-com:office:office";
string excelNamespace = "urn:schemas-microsoft-com:office:excel";
string htmlNamespace = "http://www.w3.org/TR/REC-html40";

thanks.
--
Paul G
Software engineer.
Apr 19 '07 #1
9 6059
Paul wrote:
Hi I have a .net application and am using the xml writer class to create an
xml file that opens as an excel file. I am trying to write out the following
but am having difficulty.
<Row>
<Cell ss:StyleID="s87">
<ss:Data ss: Type = "String">
<Font html:Color="#FF0000">M90</Font>
<Font>/Thu</Font>
</ss:Data>
</Cell>
This produces a cell with text with part of the text being red the M90 and
the other part being black.
I also have the following strings set up in my code
string spreadsheetNamespace = "urn:schemas-microsoft-com:office:spreadsheet";
string officeNamespace = "urn:schemas-microsoft-com:office:office";
string excelNamespace = "urn:schemas-microsoft-com:office:excel";
string htmlNamespace = "http://www.w3.org/TR/REC-html40";
We need to know whether those elements (e.g. Row, Cell) are in a
namespace and which namespace URI that namespace has. And we need to
know which namespace URI the prefix ss is bound to.

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Apr 20 '07 #2
Hi thanks for the response. When I write out the row I am using the following,
WriteStartElement("Row");
WriteAttributeString("ss","AutofitHeight","Spreads heetNamespace","0");
followed by other write statements for cells/data and closing tags.
So I am using the SpreadsheetNamespace for both rows and cells.
The SpreadsheetNamespace I have defined as
"urn:schemas-microsoft-com:office:spareadsheet". I am using the "ss" prefix
whenever the SpreadsheetNamespace is used like in the WriteAttributeString
above. I am kind of new to xml but was trying to bind it to
urn:schemas-microsoft-com:office:spreadsheet. Do I need an additional line
of code to do this or is it implied by how I am using it?
Thanks again Paul.
--
Paul G
Software engineer.
"Martin Honnen" wrote:
Paul wrote:
Hi I have a .net application and am using the xml writer class to create an
xml file that opens as an excel file. I am trying to write out the following
but am having difficulty.
<Row>
<Cell ss:StyleID="s87">
<ss:Data ss: Type = "String">
<Font html:Color="#FF0000">M90</Font>
<Font>/Thu</Font>
</ss:Data>
</Cell>
This produces a cell with text with part of the text being red the M90 and
the other part being black.
I also have the following strings set up in my code
string spreadsheetNamespace = "urn:schemas-microsoft-com:office:spreadsheet";
string officeNamespace = "urn:schemas-microsoft-com:office:office";
string excelNamespace = "urn:schemas-microsoft-com:office:excel";
string htmlNamespace = "http://www.w3.org/TR/REC-html40";

We need to know whether those elements (e.g. Row, Cell) are in a
namespace and which namespace URI that namespace has. And we need to
know which namespace URI the prefix ss is bound to.

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Apr 23 '07 #3
Also I am using a namespace when i write out the string attribute for the
cells and rows. I am using the WriteStartElement as described above to write
out the start tags for rows and cells. Thanks Paul.
--
Paul G
Software engineer.
"Paul" wrote:
Hi thanks for the response. When I write out the row I am using the following,
WriteStartElement("Row");
WriteAttributeString("ss","AutofitHeight","Spreads heetNamespace","0");
followed by other write statements for cells/data and closing tags.
So I am using the SpreadsheetNamespace for both rows and cells.
The SpreadsheetNamespace I have defined as
"urn:schemas-microsoft-com:office:spareadsheet". I am using the "ss" prefix
whenever the SpreadsheetNamespace is used like in the WriteAttributeString
above. I am kind of new to xml but was trying to bind it to
urn:schemas-microsoft-com:office:spreadsheet. Do I need an additional line
of code to do this or is it implied by how I am using it?
Thanks again Paul.
--
Paul G
Software engineer.
"Martin Honnen" wrote:
Paul wrote:
Hi I have a .net application and am using the xml writer class to create an
xml file that opens as an excel file. I am trying to write out the following
but am having difficulty.
<Row>
<Cell ss:StyleID="s87">
<ss:Data ss: Type = "String">
<Font html:Color="#FF0000">M90</Font>
<Font>/Thu</Font>
</ss:Data>
</Cell>
This produces a cell with text with part of the text being red the M90 and
the other part being black.
I also have the following strings set up in my code
string spreadsheetNamespace = "urn:schemas-microsoft-com:office:spreadsheet";
string officeNamespace = "urn:schemas-microsoft-com:office:office";
string excelNamespace = "urn:schemas-microsoft-com:office:excel";
string htmlNamespace = "http://www.w3.org/TR/REC-html40";
We need to know whether those elements (e.g. Row, Cell) are in a
namespace and which namespace URI that namespace has. And we need to
know which namespace URI the prefix ss is bound to.

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Apr 23 '07 #4
Also under the Workbook I have the following
xmlns:ss = urn:schemas-microsoft-com:office:spreadsheet

--
Paul G
Software engineer.
"Paul" wrote:
Also I am using a namespace when i write out the string attribute for the
cells and rows. I am using the WriteStartElement as described above to write
out the start tags for rows and cells. Thanks Paul.
--
Paul G
Software engineer.
"Paul" wrote:
Hi thanks for the response. When I write out the row I am using the following,
WriteStartElement("Row");
WriteAttributeString("ss","AutofitHeight","Spreads heetNamespace","0");
followed by other write statements for cells/data and closing tags.
So I am using the SpreadsheetNamespace for both rows and cells.
The SpreadsheetNamespace I have defined as
"urn:schemas-microsoft-com:office:spareadsheet". I am using the "ss" prefix
whenever the SpreadsheetNamespace is used like in the WriteAttributeString
above. I am kind of new to xml but was trying to bind it to
urn:schemas-microsoft-com:office:spreadsheet. Do I need an additional line
of code to do this or is it implied by how I am using it?
Thanks again Paul.
--
Paul G
Software engineer.
"Martin Honnen" wrote:
Paul wrote:
Hi I have a .net application and am using the xml writer class to create an
xml file that opens as an excel file. I am trying to write out the following
but am having difficulty.
<Row>
<Cell ss:StyleID="s87">
<ss:Data ss: Type = "String">
<Font html:Color="#FF0000">M90</Font>
<Font>/Thu</Font>
</ss:Data>
</Cell>
This produces a cell with text with part of the text being red the M90 and
the other part being black.
I also have the following strings set up in my code
string spreadsheetNamespace = "urn:schemas-microsoft-com:office:spreadsheet";
string officeNamespace = "urn:schemas-microsoft-com:office:office";
string excelNamespace = "urn:schemas-microsoft-com:office:excel";
string htmlNamespace = "http://www.w3.org/TR/REC-html40";
>
We need to know whether those elements (e.g. Row, Cell) are in a
namespace and which namespace URI that namespace has. And we need to
know which namespace URI the prefix ss is bound to.
>
--
>
Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
>
Apr 23 '07 #5
additional information, the spreadsheet that I am trying to copy has the
following for the section of interest.
<Cell SS:StyleID="s87">
<ss:Data SS:Type="String" xmlns="http://www.w3.org/TR/REC-html40">
<Font html:Color="#FF0000">M90</Font>
<Font/Thur<Font>
</ss:Data>
</Cell>

--
Paul G
Software engineer.
"Paul" wrote:
Hi I have a .net application and am using the xml writer class to create an
xml file that opens as an excel file. I am trying to write out the following
but am having difficulty.
<Row>
<Cell ss:StyleID="s87">
<ss:Data ss: Type = "String">
<Font html:Color="#FF0000">M90</Font>
<Font>/Thu</Font>
</ss:Data>
</Cell>
This produces a cell with text with part of the text being red the M90 and
the other part being black.
I also have the following strings set up in my code
string spreadsheetNamespace = "urn:schemas-microsoft-com:office:spreadsheet";
string officeNamespace = "urn:schemas-microsoft-com:office:office";
string excelNamespace = "urn:schemas-microsoft-com:office:excel";
string htmlNamespace = "http://www.w3.org/TR/REC-html40";

thanks.
--
Paul G
Software engineer.
Apr 23 '07 #6
Paul wrote:
Also under the Workbook I have the following
xmlns:ss = urn:schemas-microsoft-com:office:spreadsheet
Here is some sample code that should help, you merely need to use the
WriteStartElement, WriteElementString and WriteAttributeString overloads
that allow you to specify prefix, local name, namespace and value:

const string spreadsheetNamespace =
"urn:schemas-microsoft-com:office:spreadsheet";
const string officeNamespace =
"urn:schemas-microsoft-com:office:office";
const string excelNamespace =
"urn:schemas-microsoft-com:office:excel";
const string htmlNamespace = "http://www.w3.org/TR/REC-html40";

XmlWriterSettings writerSettings = new XmlWriterSettings();
writerSettings.Indent = true;
using (XmlWriter xmlWriter = XmlWriter.Create("file.xml",
writerSettings))
{
xmlWriter.WriteStartElement("Row", spreadsheetNamespace);
xmlWriter.WriteStartElement("Cell", spreadsheetNamespace);
xmlWriter.WriteAttributeString("ss", "StyleID",
spreadsheetNamespace, "s87");
xmlWriter.WriteStartElement("ss", "Data",
spreadsheetNamespace);
xmlWriter.WriteAttributeString("ss", "Type",
spreadsheetNamespace, "String");
xmlWriter.WriteAttributeString(null, "xmlns", null,
htmlNamespace);
xmlWriter.WriteStartElement("Font", htmlNamespace);
xmlWriter.WriteAttributeString("html", "Color",
htmlNamespace, "#FF0000");
xmlWriter.WriteString("M90");
xmlWriter.WriteEndElement();
xmlWriter.WriteElementString("Font", htmlNamespace,
"/Thu");
xmlWriter.WriteEndElement();
xmlWriter.WriteEndElement();
xmlWriter.WriteEndElement();
}

Result is

<Row xmlns="urn:schemas-microsoft-com:office:spreadsheet">
<Cell ss:StyleID="s87"
xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet">
<ss:Data ss:Type="String" xmlns="http://www.w3.org/TR/REC-html40">
<Font html:Color="#FF0000"
xmlns:html="http://www.w3.org/TR/REC-html40">M90</Font>
<Font>/Thu</Font>
</ss:Data>
</Cell>
</Row>

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Apr 23 '07 #7
Hi, thanks for the response. I will give it a try.
--
Paul G
Software engineer.
"Martin Honnen" wrote:
Paul wrote:
Also under the Workbook I have the following
xmlns:ss = urn:schemas-microsoft-com:office:spreadsheet

Here is some sample code that should help, you merely need to use the
WriteStartElement, WriteElementString and WriteAttributeString overloads
that allow you to specify prefix, local name, namespace and value:

const string spreadsheetNamespace =
"urn:schemas-microsoft-com:office:spreadsheet";
const string officeNamespace =
"urn:schemas-microsoft-com:office:office";
const string excelNamespace =
"urn:schemas-microsoft-com:office:excel";
const string htmlNamespace = "http://www.w3.org/TR/REC-html40";

XmlWriterSettings writerSettings = new XmlWriterSettings();
writerSettings.Indent = true;
using (XmlWriter xmlWriter = XmlWriter.Create("file.xml",
writerSettings))
{
xmlWriter.WriteStartElement("Row", spreadsheetNamespace);
xmlWriter.WriteStartElement("Cell", spreadsheetNamespace);
xmlWriter.WriteAttributeString("ss", "StyleID",
spreadsheetNamespace, "s87");
xmlWriter.WriteStartElement("ss", "Data",
spreadsheetNamespace);
xmlWriter.WriteAttributeString("ss", "Type",
spreadsheetNamespace, "String");
xmlWriter.WriteAttributeString(null, "xmlns", null,
htmlNamespace);
xmlWriter.WriteStartElement("Font", htmlNamespace);
xmlWriter.WriteAttributeString("html", "Color",
htmlNamespace, "#FF0000");
xmlWriter.WriteString("M90");
xmlWriter.WriteEndElement();
xmlWriter.WriteElementString("Font", htmlNamespace,
"/Thu");
xmlWriter.WriteEndElement();
xmlWriter.WriteEndElement();
xmlWriter.WriteEndElement();
}

Result is

<Row xmlns="urn:schemas-microsoft-com:office:spreadsheet">
<Cell ss:StyleID="s87"
xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet">
<ss:Data ss:Type="String" xmlns="http://www.w3.org/TR/REC-html40">
<Font html:Color="#FF0000"
xmlns:html="http://www.w3.org/TR/REC-html40">M90</Font>
<Font>/Thu</Font>
</ss:Data>
</Cell>
</Row>

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Apr 23 '07 #8
Hi Martin, I integrated your example into my code and looks like it wrote out
the correct stuff when viewed with notepad but when I open the file in excel
for that cell I get M90 /Thur with empty spaces between the strings.
Also they are both colored black so seems like the Color #FF0000 is not
working. Any suggestions on what might be wrong? Thanks .
--
Paul G
Software engineer.
"Martin Honnen" wrote:
Paul wrote:
Also under the Workbook I have the following
xmlns:ss = urn:schemas-microsoft-com:office:spreadsheet

Here is some sample code that should help, you merely need to use the
WriteStartElement, WriteElementString and WriteAttributeString overloads
that allow you to specify prefix, local name, namespace and value:

const string spreadsheetNamespace =
"urn:schemas-microsoft-com:office:spreadsheet";
const string officeNamespace =
"urn:schemas-microsoft-com:office:office";
const string excelNamespace =
"urn:schemas-microsoft-com:office:excel";
const string htmlNamespace = "http://www.w3.org/TR/REC-html40";

XmlWriterSettings writerSettings = new XmlWriterSettings();
writerSettings.Indent = true;
using (XmlWriter xmlWriter = XmlWriter.Create("file.xml",
writerSettings))
{
xmlWriter.WriteStartElement("Row", spreadsheetNamespace);
xmlWriter.WriteStartElement("Cell", spreadsheetNamespace);
xmlWriter.WriteAttributeString("ss", "StyleID",
spreadsheetNamespace, "s87");
xmlWriter.WriteStartElement("ss", "Data",
spreadsheetNamespace);
xmlWriter.WriteAttributeString("ss", "Type",
spreadsheetNamespace, "String");
xmlWriter.WriteAttributeString(null, "xmlns", null,
htmlNamespace);
xmlWriter.WriteStartElement("Font", htmlNamespace);
xmlWriter.WriteAttributeString("html", "Color",
htmlNamespace, "#FF0000");
xmlWriter.WriteString("M90");
xmlWriter.WriteEndElement();
xmlWriter.WriteElementString("Font", htmlNamespace,
"/Thu");
xmlWriter.WriteEndElement();
xmlWriter.WriteEndElement();
xmlWriter.WriteEndElement();
}

Result is

<Row xmlns="urn:schemas-microsoft-com:office:spreadsheet">
<Cell ss:StyleID="s87"
xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet">
<ss:Data ss:Type="String" xmlns="http://www.w3.org/TR/REC-html40">
<Font html:Color="#FF0000"
xmlns:html="http://www.w3.org/TR/REC-html40">M90</Font>
<Font>/Thu</Font>
</ss:Data>
</Cell>
</Row>

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Apr 23 '07 #9
Thanks for the help, got it working. I had to write stuff out all on one
line to get rid of the spaces between M90 and /thur.

--
Paul G
Software engineer.
"Martin Honnen" wrote:
Paul wrote:
Also under the Workbook I have the following
xmlns:ss = urn:schemas-microsoft-com:office:spreadsheet

Here is some sample code that should help, you merely need to use the
WriteStartElement, WriteElementString and WriteAttributeString overloads
that allow you to specify prefix, local name, namespace and value:

const string spreadsheetNamespace =
"urn:schemas-microsoft-com:office:spreadsheet";
const string officeNamespace =
"urn:schemas-microsoft-com:office:office";
const string excelNamespace =
"urn:schemas-microsoft-com:office:excel";
const string htmlNamespace = "http://www.w3.org/TR/REC-html40";

XmlWriterSettings writerSettings = new XmlWriterSettings();
writerSettings.Indent = true;
using (XmlWriter xmlWriter = XmlWriter.Create("file.xml",
writerSettings))
{
xmlWriter.WriteStartElement("Row", spreadsheetNamespace);
xmlWriter.WriteStartElement("Cell", spreadsheetNamespace);
xmlWriter.WriteAttributeString("ss", "StyleID",
spreadsheetNamespace, "s87");
xmlWriter.WriteStartElement("ss", "Data",
spreadsheetNamespace);
xmlWriter.WriteAttributeString("ss", "Type",
spreadsheetNamespace, "String");
xmlWriter.WriteAttributeString(null, "xmlns", null,
htmlNamespace);
xmlWriter.WriteStartElement("Font", htmlNamespace);
xmlWriter.WriteAttributeString("html", "Color",
htmlNamespace, "#FF0000");
xmlWriter.WriteString("M90");
xmlWriter.WriteEndElement();
xmlWriter.WriteElementString("Font", htmlNamespace,
"/Thu");
xmlWriter.WriteEndElement();
xmlWriter.WriteEndElement();
xmlWriter.WriteEndElement();
}

Result is

<Row xmlns="urn:schemas-microsoft-com:office:spreadsheet">
<Cell ss:StyleID="s87"
xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet">
<ss:Data ss:Type="String" xmlns="http://www.w3.org/TR/REC-html40">
<Font html:Color="#FF0000"
xmlns:html="http://www.w3.org/TR/REC-html40">M90</Font>
<Font>/Thu</Font>
</ss:Data>
</Cell>
</Row>

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Apr 23 '07 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: jason hirst | last post by:
Hi, I've created a simple application that reads data from a SQL Server, and appends this to an XML file. The problem is, that the XML data structure seems to go to the top level when I write...
2
by: FrzzMan | last post by:
The first time I called this function, everything went well, but the second time I called it. An Exception thrown, do you know why? An unhandled exception of type 'System.IO.IOException' occurred...
3
by: John A Grandy | last post by:
When writing rss xml to the client browser , is there any reason to load the rss xml string into an XmlDocument and then Response.Write() the XmlDocument.OuterXML.ToString() ? option 1: ...
2
by: darrel | last post by:
We've been using xmltextwriter to write XML files to the filesystem. For various reasons, we're ditching the filesystem and want to store the XML as text in a DB field. Looking at all the...
11
by: ericms | last post by:
Can anybody show me how to insert a CDATA section using XPathNavigator ? I have tried the follwing with no luck: XmlDocument docNav = new XmlDocument(); docNav.LoadXml(xmlString);...
1
by: Nick | last post by:
I am working on a website for a client and one of their requirements was to have a mailing list. I decided to XSLT to transform "templates" to HTML so that editing was very easy and less time...
4
by: Anthoni | last post by:
Dear All, I need to export data of unbound datagridview to XML file. Since my DataSource is NULL, What other options do I have? Does i need to make 2 loops (on all the records and inside loop of...
1
by: depalau | last post by:
I'm experiencing issues where XmlSerialier.Deserialize throws an exception when attempting to use a MemoryStream built with an XmlWriter vs. a standalone StringReader. It is attempting to...
0
by: MedIt | last post by:
Hi all, Help needed in the xsl transformation in c# while passing with arguments. I am trying to transform an xml programtically (c#), while passing with two parameters using the XsltArgumentList...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.