Now I am face the problem.
First I created a DataSet from a xlsx file. And I had to keep the style so I can display it on web.
Here is my code
string GetText(string xml)
{
XDocument xdoc = XDocument.Parse(xml);
XNamespace space = @"http://schemas.openxmlformats.org/spreadsheetml/2006/main";
XElement element = xdoc.Element(space + "si");
if (element == null) return "";
StringBuilder sbText = new StringBuilder();
string str = "";
if (element.Element(space + "r") != null)
{
foreach (XElement xr in element.Elements(space + "r"))
{
str = "";
if ((xr.Element(space + "t") != null))
{
str = xr.Element(space + "t").Value;
if (string.IsNullOrEmpty(str)) continue;
if (xr.Element(space + "rPr") != null)
{
XElement rpr = xr.Element(space + "rPr");
if (rpr.Element(space + "b") != null) str = "<b>" + str + "</b>";
if (rpr.Element(space + "u") != null) str = "<u>" + str + "</u>";
if (rpr.Element(space + "i") != null) str = "<i>" + str + "</i>";
}else if (xr.Element(space + "rpr") != null)
{
XElement rpr = xr.Element(space + "rpr");
if (rpr.Element(space + "b") != null) str = "<b>" + str + "</b>";
if (rpr.Element(space + "u") != null) str = "<u>" + str + "</u>";
if (rpr.Element(space + "i") != null) str = "<i>" + str + "</i>";
}
}
sbText.Append(str);
}
}
else if (element.Element(space + "t") != null) return element.Element(space + "t").Value;
return sbText.ToString();
}
It work well. But This is not over. All the text I get is store as xml file.
This is the main work, Get message from xml file, and then rewrite it into a new xlsx file.
The problem is, How can I Keep the <b>,<u>,<i> style in the xlsx file.
Because the tag <b> or <i> or <u> in xlsx table is text, not style.