使用OPENXML在MSSQL 2005中获取dt元素.如何在xml中获取xmlns:dt元素?例如,获取列出产品ID和国家/地区代码的两行结果集.
121403 GBR
121403美国
declare @xmldata xml
set @xmldata =
'<?xml version="1.0"?>
<data xmlns="http://www.aaa.com/master_browse_response" xmlns:dt="http://www.aaa.com/DataTypes">
<products>
<product>
<product_id><![CDATA[121403]]></product_id>
<countries>
<dt:country>GBR</dt:country>
<dt:country>USA</dt:country>
</countries>
</product>
</products>
</data>'
DECLARE @hDoc int, @rootxmlns varchar(100)
SET @rootxmlns = '<root xmlns:hm="http://www.aaa.com/master_browse_response"/>'
EXEC sp_xml_preparedocument @hDoc OUTPUT, @xmldata, @rootxmlns
SELECT *
FROM OPENXML(@hDoc, '//hm:product',2)
WITH ([hm:product_id] int , [hm:countries] varchar(100))
--clean up
EXEC sp_xml_removedocument @hDoc
Run Code Online (Sandbox Code Playgroud)
这是我通过使用xmlEdgeTable知道的一个解决方案,但我正在寻找更好的解决方案.
DECLARE @hDoc int, @rootxmlns varchar(100)
SET @rootxmlns = '<root xmlns:hm="http://www.aaa.com/master_browse_response"/>'
EXEC sp_xml_preparedocument @hDoc OUTPUT, @xmldata, @rootxmlns
CREATE TABLE #xmlEdgeTable
(
id …Run Code Online (Sandbox Code Playgroud) 我使用OpenXML库获取数据表并将其粘贴到预格式化的excel文件中.这很好用.
我遇到的问题是在预格式化的excel文件的顶部有一个小计行,它被设置为对该数据的每一列进行小计(因此在每列的顶部有一个小计).当我在创建excel文件后打开它时,这些值都设置为0,它们在插入数据表时没有更新.如果您突出显示其中一个小计单元格然后按Enter键,它将更新并显示正确的值.
一旦用户打开下载的电子表格,最简单的方法是让这些值更新并显示正确的值?
创建电子表格的代码:
MemoryStream memoryStream = SpreadsheetReader.StreamFromFile(TemplateDirectory + @"\" + "exceltTemplate.xlsx");
doc = SpreadsheetDocument.Open(memoryStream, true);
worksheetPart = SpreadsheetReader.GetWorksheetPartByName(doc, currentSheetName);
writer = new WorksheetWriter(doc, worksheetPart);
cellName = "A8";
writer.PasteDataTable(reports.Tables[0], cellName);
SpreadsheetWriter.Save(doc);
Run Code Online (Sandbox Code Playgroud) 我在SQL Server表中有此XML:
<root>
<meetings>
<meeting>
<id>111</id>
<participants>
<participant><name>Smith</name></participant>
<participant><name>Jones</name></participant>
<participant><name>Brown</name></participant>
</participants>
</meeting>
<meeting>
<id>222</id>
<participants>
<participant><name>White</name></participant>
<participant><name>Bloggs</name></participant>
<participant><name>McDonald</name></participant>
</participants>
</meeting>
</meetings>
</root>
Run Code Online (Sandbox Code Playgroud)
并想要这样的结果集:
MeetingID Name
111 Smith
111 Jones
111 Brown
222 White
222 Bloggs
222 McDonald
Run Code Online (Sandbox Code Playgroud)
这很容易使用,select from openxml但是我无法使用XQuery。有人可以帮我在那儿,也许也可以对每种方法都有优缺点?
大家好我想尝试以mvc3中的表格的形式将一些数据导出到excel.这是我用来生成excel文件的类:
//------------------------------------------------------------------------------
// <copyright file="ExcelDocument.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
// <summary>The Export to Excel Document class.</summary>
// ----------------------------------------------------------------------------
namespace ExporToExcel.Controllers.ControllerExtensions
{
using System;
using System.IO;
using System.Linq;
using DocumentFormat.OpenXml;
using DocumentFormat.OpenXml.Extensions;
using DocumentFormat.OpenXml.Packaging;
using DocumentFormat.OpenXml.Spreadsheet;
/// <summary>
/// Excel document.
/// </summary>
public static class ExcelDocument
{
/// <summary>
/// Default spread sheet name.
/// </summary>
private const string DefaultSheetName = "Sheet1";
/// <summary>
/// Create the exel document for streaming.
/// </summary> …Run Code Online (Sandbox Code Playgroud) 我有在控制台中创建文件的基本代码(请参见下文)。但是我正在编写MVC应用程序,因此我需要将XML文档作为ActionResult返回。没有运气的例子。
我要添加什么使其成为ActionResult?
string filePath = @"C:\temp\OpenXMLTest.docx";
using (WordprocessingDocument doc = WordprocessingDocument.Create(filePath, WordprocessingDocumentType.Document))
{
//// Creates the MainDocumentPart and add it to the document (doc)
MainDocumentPart mainPart = doc.AddMainDocumentPart();
mainPart.Document = new Document(
new Body(
new Paragraph(
new Run(
new Text("Hello World!!!!!")))));
}
Run Code Online (Sandbox Code Playgroud) 我需要得到w:来自w的lvl文本:ilvl
我能够获得w:ilvl值但是仍然坚持如何从这里开始如何将w:ilvl链接到w:编号(我知道我必须使用w:在.net中的ilvl,但是如何从代码方面做到这一点?documnet.xml的代码片段粘贴在下面.我需要获取单元格文本形式w:ilvl
<w:tc>
<w:tcPr>
<w:tcW w:w="990" w:type="dxa" />
</w:tcPr>
<w:p w:rsidRPr="006D6DAA" w:rsidR="008F1408" w:rsidP="00012A9D" w:rsidRDefault="008F1408">
<w:pPr>
<w:pStyle w:val="Table-Left" />
<w:numPr>
<w:ilvl w:val="0" />
<w:numId w:val="13" />
</w:numPr>
<w:rPr>
<w:sz w:val="18" />
</w:rPr>
</w:pPr>
</w:p>
</w:tc>
Run Code Online (Sandbox Code Playgroud) 有谁知道是否可以在SpreadsheetLight中检索公式的数值?如果没有可以在OpenXml中读取公式为数字?
我需要为cellValue(8,1)返回7.07
public static void TestSlWorkbook()
{
SLDocument sl = new SLDocument();
sl.SetCellValue(1, 1, 1.01);
sl.SetCellValue(2, 1, 1.01);
sl.SetCellValue(3, 1, 1.01);
sl.SetCellValue(4, 1, 1.01);
sl.SetCellValue(5, 1, 1.01);
sl.SetCellValue(6, 1, 1.01);
sl.SetCellValue(7, 1, 1.01);
sl.SetCellValue(8, 1, "=Sum(A1:A7)");
}
Run Code Online (Sandbox Code Playgroud) 我想删除包含的段落"{Some Text}".下面的方法就是这样,但是我注意到在删除段落后,剩下的是空段落元素.
如何以<w:p />编程方式删除元素?
以下是我最初用来删除段落的内容.
using (WordprocessingDocument wordDoc = WordprocessingDocument.Open(file, true))
{
MainDocumentPart mainPart = wordDoc.MainDocumentPart;
Document D = mainPart.Document;
foreach (Paragraph P in D.Descendants<Paragraph>())
{
if (P.InnerText.Contains("{SomeText}"))
{
P.RemoveAllChildren();
//P.Remove(); //doesn't remove
}
}
D.Save();
}
Run Code Online (Sandbox Code Playgroud)
这就是document.xml的后缀:
<w:p />
<w:p />
<w:p />
<w:p />
<w:p />
<w:p />
<w:p />
Run Code Online (Sandbox Code Playgroud) 从一段时间以来,我一直在努力将数据从db(存储过程)导出到excel文件.当我处理大量数据(每张大约500k行,不幸的是业务需求)时,我想知道是否有可能对单个工作表执行并行写入.我正在使用EPPlus和OpenXML来写入文件.当我通过网络阅读时,我能够理解用户定义的函数可以并行执行,但我没有找到任何并行写入的东西.任何帮助/建议/提示/等.将不胜感激!
我试图设置细胞样式,我不能让颜色正常工作,我正在使用以下填充:
// <Fills>
Fill fill0 = new Fill(); // Default fill
Fill fill1 = new Fill(
new PatternFill(
new ForegroundColor() { Rgb = new HexBinaryValue() { Value = "DCDCDC" } }
)
{ PatternType = PatternValues.Solid });
Fills fills = new Fills(); // appending fills
fills.Append(fill0);
fills.Append(fill1);
CellFormat _0_default = new CellFormat() { FontId = 0, FillId = 0, BorderId = 0 }; // Default style : Mandatory | Style ID =0
CellFormat _1_header = new CellFormat() { FontId = …Run Code Online (Sandbox Code Playgroud) openxml ×10
c# ×4
openxml-sdk ×3
excel ×2
ms-word ×2
sql-server ×2
.net ×1
asp.net ×1
asp.net-mvc ×1
epplus ×1
office-2007 ×1
sql ×1
t-sql ×1
xml ×1
xquery ×1