打开记忆XML字符串作为一个Excel工作簿,但不保存使用Windows窗体C# [英] Open in memory XML string as an Excel workbook without saving using windows Forms C#
本文介绍了打开记忆XML字符串作为一个Excel工作簿,但不保存使用Windows窗体C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个Excel字符串(我建)内存;代码看起来是这样的:
I have an excel string (which I built) in memory; the code looks something like this:
public static void exportToExcel()
{
const string startExcelXML = "<xml version>\r\n<Workbook " +
"xmlns=\"urn:schemas-microsoft-com:office:spreadsheet\"\r\n"
+
" xmlns:o=\"urn:schemas-microsoft-com:office:office\"\r\n " +
"xmlns:x=\"urn:schemas- microsoft-com:office:" +
"excel\"\r\n xmlns:ss=\"urn:schemas-microsoft-com:"
+
"office:spreadsheet\">\r\n <Styles>\r\n " +
"<Style ss:ID=\"Default\" ss:Name=\"Normal\">\r\n " +
"<Alignment ss:Vertical=\"Bottom\"/>\r\n <Borders/>" +
"\r\n <Font/>\r\n <Interior/>\r\n <NumberFormat/>" +
"\r\n <Protection/>\r\n </Style>\r\n " +
"<Style ss:ID=\"BoldColumn\">\r\n <Font " +
"x:Family=\"Swiss\" ss:Bold=\"1\"/>\r\n </Style>\r\n " +
"<Style ss:ID=\"StringLiteral\">\r\n <NumberFormat" +
" ss:Format=\"@\"/>\r\n </Style>\r\n <Style " +
"ss:ID=\"Decimal\">\r\n <NumberFormat/>\r\n </Style>\r\n " +
"<Style ss:ID=\"Integer\">\r\n <NumberFormat "
+
"ss:Format=\"0\"/>\r\n </Style>\r\n <Style " +
"ss:ID=\"DateLiteral\">\r\n <NumberFormat " +
"ss:Format=\"dd/mm/yyyy;@\"/>\r\n </Style>\r\n " +
"</Styles>\r\n ";
const string endExcelXML = "</Workbook>";
int sheetCount = 1;
StringBuilder sb = new StringBuilder();
sb.Append(startExcelXML);
sb.Append("<Worksheet ss:Name=\"Sheet" + sheetCount + "\">");
sb.Append("<Table>");
sb.Append("<Row>");
sb.Append("<Cell ss:StyleID=\"BoldColumn\"><Data ss:Type=\"String\">");
sb.Append("Home country");
sb.Append("</Data></Cell>");
sb.Append("<Cell ss:StyleID=\"BoldColumn\"><Data ss:Type=\"String\">");
sb.Append("Expatriation Type");
sb.Append("</Data></Cell>");
sb.Append("</Row>");
sb.Append("<Row>");
sb.Append("<Cell ss:StyleID=\"StringLiteral\">" +
"<Data ss:Type=\"String\">");
sb.Append("Singapore");
sb.Append("</Data></Cell>");
sb.Append("<Cell ss:StyleID=\"StringLiteral\">" +
"<Data ss:Type=\"String\">");
sb.Append("Benchmark");
sb.Append("</Data></Cell>");
sb.Append("</Row>");
sb.Append("</Table>");
sb.Append(" </Worksheet>");
sb.Append(endExcelXML);
}
我能够打开该文件为excel表只有当我保存体力文件;但是否有任何其他方式只需打开从内存中Excel工作表的XML字符串?
I able to open the file as excel sheet only if I save the file physically; but is there any other way to just open the xml string from the memory as excel sheet?
推荐答案
我想你会需要的是某种类型的内存映射文件执行。
I think what you'll need is a memory mapped file implementation of some kind.
我相信,虽然,.NET 4.0将内置于 MemoryMappedFile
的支持。
I believe, though, that .NET 4.0 will have built-in MemoryMappedFile
support.
您可能能够找到使用搜索引擎等.NET实现。
You may be able to find other .net implementations using a search engine.
这篇关于打开记忆XML字符串作为一个Excel工作簿,但不保存使用Windows窗体C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文