我正在编写一个 xlsx 文件,我想将自己的样式应用到工作表中的单元格。我有一个情况,样式 1 和样式 2 都指定纯红色,但是当我在 Excel 中打开它时,第一个是灰色点画,但第二个是我所期望的。我很困惑..以下是附件中的一些 xml 内容。
在工作表中,我有 2 个单元格:
<x:c t="inlineStr" s="2">
<x:is>
<x:t>looks right</x:t>
</x:is>
</x:c>
<x:c t="inlineStr" s="1">
<x:is>
<x:t>looks wrong</x:t>
</x:is>
</x:c>
Run Code Online (Sandbox Code Playgroud)
在 styles.xml 文件中,我定义这些单元格样式如下:
<x:cellXfs>
<x:xf borderId="0" fillId="0" fontId="0" numFmtId="0"/>
<x:xf fillId="1" applyFill="1"/>
<x:xf fillId="2" applyFill="1"/>
</x:cellXfs>
Run Code Online (Sandbox Code Playgroud)
填充的位置是:
<x:fills>
<x:fill>
<x:patternFill patternType="none"/>
</x:fill>
<x:fill>
<x:patternFill patternType="solid">
<x:fgColor rgb="FFFF0000"/>
</x:patternFill>
</x:fill>
<x:fill>
<x:patternFill patternType="solid">
<x:fgColor rgb="FFFF0000"/>
</x:patternFill>
</x:fill>
</x:fills>
Run Code Online (Sandbox Code Playgroud)
填充 1 和 2 都是纯红色,因此单元格样式 1 和 2 应该相同,对吗?但他们不是。
这是 Excel 错误吗?是否有一个编号为 1 …
我正在使用 OpenXML 创建 Microsoft Excel 文件。我正在尝试使用以下命令将双精度类型变量(示例:4.987456789)插入Excel中
Cell cell = new Cell()
{
CellReference = "A2",
DataType = CellValues.String,
CellValue = new CellValue(Convert.ToString(value))
};
Run Code Online (Sandbox Code Playgroud)
但是,当创建单元格时,它是文本形式的,Excel 会显示“此单元格中的数字格式为文本或前面带有撇号”。如何格式化单元格以插入双精度?
编辑:抱歉,是双倍的吗?输入并按照本教程进行操作
我正在使用NET 3.5 库System.Drawing.Bitmap中的类System.Drawing。
代码是这样的:
Bitmap bm = new Bitmap(filename);
Console.WriteLine("bm.width: " + bm.width); // RETURNS 233, RIGHT AMOUNT
Console.WriteLine("bm.HorizontalResolution: " + bm.HorizontalResolution); // RETURNS 0!!
Run Code Online (Sandbox Code Playgroud)
有谁有我可以使用的不同兼容类,或者单声道的任何技巧可以使这项工作正常进行?我需要在 Word 中正确缩放图像的分辨率(我正在生成 .docx 文件)。
Mono JIT compiler version 3.2.8 (Debian 3.2.8+dfsg-4ubuntu1)
Copyright (C) 2002-2014 Novell, Inc, Xamarin Inc and Contributors. www.mono-project.com
Run Code Online (Sandbox Code Playgroud)
System.Drawing.Image具有相同的行为。
我正在尝试使用 OpenXML 将 Word 文件中的合并字段替换为我的数据。
\n\n我认为代码中没有问题,因为有时它在某些模板中工作正常,有时合并字段没有被替换。
\n\n在word模板中插入合并域有问题吗?我不知道出了什么问题。
\n\n下面是我使用的代码:
\n\n public void Fill_Document_Fields(Dictionary<string, string> Fields, string FilePath)\n {\n try\n {\n using (WordprocessingDocument Doc = WordprocessingDocument.Open(FilePath, true))\n {\n foreach (FieldCode field in Doc.MainDocumentPart.RootElement.Descendants<FieldCode>())\n {\n string FieldName =string.Empty;\n try\n {\n FieldName = field.Text.Trim().Split(\' \')[2];\n }\n catch\n {\n FieldName = field.Text.Trim();\n }\n\n\n foreach (Run run in Doc.MainDocumentPart.Document.Descendants<Run>())\n {\n foreach (Text txtFromRun in run.Descendants<Text>().Where(a => a.Text == "\xc2\xab" + FieldName + "\xc2\xbb"))\n {\n string itemValue;\n if (Fields.TryGetValue(txtFromRun.Text, out itemValue))\n {\n txtFromRun.Text = …Run Code Online (Sandbox Code Playgroud) 我正在使用 OpenXml 将大数据转换为 Excel,并且我正在使用以下导出到 Excel 类
http://www.codeproject.com/Articles/692092/A-free-Export-to-Excel-Csharp-class-using-OpenXML
下面是我班级中的代码。
public static bool CreateExcelDocumentAsStream(DataSet ds, string filename, System.Web.HttpResponse Response)
{
try
{
System.IO.MemoryStream stream = new System.IO.MemoryStream();
using (SpreadsheetDocument document = SpreadsheetDocument.Create(stream, SpreadsheetDocumentType.Workbook, true))
{
WriteExcelFile(ds, document);
}
stream.Flush();
stream.Position = 0;
Response.ClearContent();
Response.Clear();
Response.Buffer = true;
Response.Charset = "";
// NOTE: If you get an "HttpCacheability does not exist" error on the following line, make sure you have
// manually added System.Web to this project's References.
Response.Cache.SetCacheability(System.Web.HttpCacheability.NoCache);
Response.AddHeader("content-disposition", "attachment; filename=" + …Run Code Online (Sandbox Code Playgroud) 我正在使用DocumentFormat.OpenXml读取 Excel 电子表格。我有一个性能瓶颈,用于从SharedStringTable对象中查找单元格值的代码(它似乎是某种单元格值的查找表):
var returnValue = sharedStringTablePart.SharedStringTable.ChildElements.GetItem(parsedValue).InnerText;
Run Code Online (Sandbox Code Playgroud)
我创建了一个字典以确保我只检索一次值:
if (dictionary.ContainsKey(parsedValue))
{
return dictionary[parsedValue];
}
var fetchedValue = sharedStringTablePart.SharedStringTable.ChildElements.GetItem(parsedValue).InnerText;
dictionary.Add(parsedValue, fetchedValue);
return fetchedValue;
Run Code Online (Sandbox Code Playgroud)
这将性能时间减少了近 50%。但是,我的指标表明,从SharedStringTable对象中获取值的代码行执行 123,951 次仍然需要 208 秒。有没有其他方法可以优化这个操作?
我用 OpenXML 制作了这个文档。. 我正在学习 OpenXML。哦。。太难了。
MainDocumentPart m = wd.AddMainDocumentPart();
m.Document = new Document();
Body b1 = new Body();
int myCount = 5;
for (int z = 1; z <= myCount; z++)
{
Paragraph p1 = new Paragraph();
Run r1 = new Run();
Text t1 = new Text(
"The Quick Brown Fox Jumps Over The Lazy Dog " + z );
r1.Append(t1);
p1.Append(r1);
b1.Append(p1);
}
m.Document.Append(b1);
Run Code Online (Sandbox Code Playgroud)
我想改变它的方向从纵向 - >横向并将其边距设置得更小。
加工前;
我可以用这样的 VBA 代码实现这个目标;
With ActiveDocument.PageSetup
.Orientation = wdOrientLandscape
.TopMargin …Run Code Online (Sandbox Code Playgroud) 我是一名教师。我想要一份所有对我布置的文章发表评论的学生的名单,以及他们说了什么。Drive API 的东西对我来说太具有挑战性了,但我想我可以将它们作为 zip 下载并解析 XML。
评论被标记在w:comment标签中,w:t用于评论文本和 。这应该很容易,但是 XML (etree) 正在杀死我。
通过教程(和官方 Python 文档):
z = zipfile.ZipFile('test.docx')
x = z.read('word/comments.xml')
tree = etree.XML(x)
Run Code Online (Sandbox Code Playgroud)
然后我这样做:
children = tree.getiterator()
for c in children:
print(c.attrib)
Run Code Online (Sandbox Code Playgroud)
结果是这样:
{}
{'{http://schemas.openxmlformats.org/wordprocessingml/2006/main}author': 'Joe Shmoe', '{http://schemas.openxmlformats.org/wordprocessingml/2006/main}id': '1', '{http://schemas.openxmlformats.org/wordprocessingml/2006/main}date': '2017-11-17T16:58:27Z'}
{'{http://schemas.openxmlformats.org/wordprocessingml/2006/main}rsidR': '00000000', '{http://schemas.openxmlformats.org/wordprocessingml/2006/main}rsidDel': '00000000', '{http://schemas.openxmlformats.org/wordprocessingml/2006/main}rsidP': '00000000', '{http://schemas.openxmlformats.org/wordprocessingml/2006/main}rsidRDefault': '00000000', '{http://schemas.openxmlformats.org/wordprocessingml/2006/main}rsidRPr': '00000000'}
{}
{'{http://schemas.openxmlformats.org/wordprocessingml/2006/main}val': '0'}
{'{http://schemas.openxmlformats.org/wordprocessingml/2006/main}val': '0'}
{'{http://schemas.openxmlformats.org/wordprocessingml/2006/main}val': '0'}
Run Code Online (Sandbox Code Playgroud)
在此之后,我完全被困住了。我试着element.get()和element.findall()没有运气。即使我复制/粘贴值 ( '{http://schemas.openxmlformats.org/wordprocessingml/2006/main}val'),我也会得到None回报。
任何人都可以帮忙吗?
我想使用 Apache POI 对 OOXML 文件启用密码保护。
通过 Office 程序,在保存文件 ( pptx, xlsx, ...) 时,我可以选择,Tools > Options并且会提示我设置打开和/或更改文件的密码。
现在我通过谷歌搜索了几个小时并阅读了一些 API 页面以找到这样做的 POI 方法,但找不到任何东西。
知道这是实施的还是 Microsoft 的专长,因为他们根本不在乎自己的标准化?
编辑:由于下面的第一条评论指向 Office 2003 文档,我可能会明确指出:我在谈论 XSS* 功能。我想从 2007 年开始保护 OOXML 格式。我在不同的 API 上查找了类似的函数,但找不到那些。HSSWorkBook#writeProtect... 我知道。
这是我修改 PowerPoint 演示文稿、将其另存为新文件、关闭它,然后尝试打开该文件的代码。
var doc = PresentationDocument.Open(@"d:\temp.pptx", true);
//... proccess presentation
doc.SaveAs(@"d:\temp2.pptx");
doc.Close();
var doc2 = PresentationDocument.Open(@"d:\temp2.pptx", false);
doc2.Close();
Run Code Online (Sandbox Code Playgroud)
我不明白为什么运行时会抛出异常:
该进程无法访问文件“x”,因为它正被另一个进程使用。
openxml ×10
c# ×6
excel ×3
openxml-sdk ×3
.net ×2
c#-4.0 ×2
xml ×2
.net-3.5 ×1
apache-poi ×1
asp.net ×1
docx ×1
google-docs ×1
java ×1
mono ×1
ms-office ×1
ms-word ×1
powerpoint ×1
python ×1