我正在将 docx 转换为 html 格式(使用 apache poi)并将其作为电子邮件发送。
生成的 html 片段看起来像这样
<html>
<head>
....
<style>
span.Normal{
font-family: 'Arial';font-size: 9.0pt;
}
span.Title{
font-family: 'Cambria';font-size: 28.0pt;color: #000000;
}
span.MySubtitle{
font-family: 'Arial';font-size: 18.0pt;color: #000000;
}
span.MyTitle{
font-family: 'Arial';font-size: 22.0pt;font-weight: bold;color: #000000;
}
...
</style>
</head>
<body>
....
<p class="Normal Title MyTitle">
<span id="_GoBack">
<span class="Normal Title MyTitle">Welcome Message</span>
<span class="Normal Title MyTitle"> </span>
<span class="Normal Title MyTitle">Username</span>
</p>
<p class="Normal Title MySubtitle">
<span class="Normal Title MySubtitle">Issues and Solutions</span>
</p>
...
</body>
</html>Run Code Online (Sandbox Code Playgroud)
Outlook 客户端无法识别多个 …
我的 C# 应用程序使用 OpenXML 创建一个 MSWord 文档,其中已包含多个表。最后一部分是添加条形图。我找不到这个案例的好例子。
感谢您的帮助!
我正在从头开始创建该文档。从...开始:
using (WordprocessingDocument myDoc = WordprocessingDocument.Create(documentStream, WordprocessingDocumentType.Document, autoSave: true))
Run Code Online (Sandbox Code Playgroud)
然后我在 C# 代码中添加新的表格和段落。在我到达条形图之前,所有这些都在起作用。我找到了一个示例项目,它将饼图插入到Word文档中,但我不明白转换它的图表类型之间的差异。这是我找到的饼图示例项目:
https://code.msdn.microsoft.com/office/How-to-create-Chart-into-a7d424f6
感谢您的帮助!
谁能告诉我我的代码中缺少什么?它运行时没有任何错误,但不会写入我的 Excel 文件。我只是想让它写入电子表格“商业”选项卡上的单元格 A1。
我的代码如下:
using System;
using System.Data;
using Microsoft.SqlServer.Dts.Runtime;
using System.Windows.Forms;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.IO;
using System.Reflection;
using System.Data.OleDb;
using DocumentFormat.OpenXml;
using DocumentFormat.OpenXml.Packaging;
using DocumentFormat.OpenXml.Spreadsheet;
using System.Xml;
using System.Diagnostics;
namespace Application.Model
{
[Microsoft.SqlServer.Dts.Tasks.ScriptTask.SSISScriptTaskEntryPointAttribute]
public class TempCode : Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTARTScriptObjectModelBase
{
string FilePath;
string FileName;
string FileExceptionsPath;
string FileExceptionsName;
string Exceptions = "";
public void Main()
{
try
{
FilePath = (string)Dts.Variables["FilePath"].Value;
FileName = (string)Dts.Variables["User::FileName"].Value;
FileExceptionsPath = (string)Dts.Variables["FileExceptionsPath"].Value;
FileExceptionsName = (string)Dts.Variables["User::FileExceptionsName"].Value;
Dts.Variables["User::FileAbsolutePath"].Value = (string)Dts.Variables["FilePath"].Value …Run Code Online (Sandbox Code Playgroud) 我开发了一个应用程序,该应用程序应该将图像添加到Word文档中。它从 Word 文档中获取副本并将图片添加到副本中。我尝试添加文本,效果很好,但是通过添加图像,word 文档想要打开一个文件,并给出错误(无法打开文件“名称”,因为内容存在问题。)
我的代码如下所示:
File.Copy(file, newFile, true);
WordprocessingDocument wordFile = WordprocessingDocument.Open(newFile, true);
Body body = wordFile.MainDocumentPart.Document.Body;
var picture = new Picture();
var shape = new Shape() { Style = "width: 20px; height: 20px" };
var imageData = new ImageData() { RelationshipId = "img" };
shape.Append(imageData);
picture.Append(shape);
wordFile.MainDocumentPart.AddExternalRelationship(
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/image",
new Uri(link_of_image, UriKind.Absolute),"img");
Paragraph para = body.AppendChild(new Paragraph());
Run run = para.AppendChild(new Run());
run.AppendChild(new Picture(picture));
wordFile.Close();
Run Code Online (Sandbox Code Playgroud)
可能出什么问题了?
我有一个 C# 网络应用程序。我正在使用 xlsx 模板来创建文档。xlsx 的格式相当复杂,因此我选择了模板路线,而不是从头开始创建。在 x2 单元格中,大多数数据以百分比形式出现,但在某些情况下,它会是一个金额。但当该单元格的数量为百分比时,我似乎无法更改该单元格的格式。模板以百分比格式保存在该单元格中。设置单元格值的代码如下,适用于以货币格式保存的其他单元格。我尝试根据另一个具有相同格式的单元格中的代码将单元格样式索引设置为 103U。
如何更改单元格 x2 的格式?任何帮助将不胜感激。预先感谢。`
public void setCellValueNum(WorksheetPart ws, int row, int col, Double newVal)
{
Cell cl = getCell(ws.Worksheet, getColLetter(col), row);
cl.CellValue = new CellValue(newVal.ToString());
cl.CellReference = getColLetter(col) + row.ToString();
cl.DataType =
new EnumValue<CellValues>(CellValues.Number);
//cl.StyleIndex = (UInt32Value)103U;
}
Run Code Online (Sandbox Code Playgroud) 我在更新由 Linux 上的python-docx生成的 docx 文件中的目录时遇到问题。一般来说,创建TOC并不难(感谢这个答案/sf/answers/3403559211/和这个线程https://github.com/python-openxml/python-docx/issues/36)
from docx.oxml.ns import qn
from docx.oxml import OxmlElement
paragraph = self.document.add_paragraph()
run = paragraph.add_run()
fldChar = OxmlElement('w:fldChar') # creates a new element
fldChar.set(qn('w:fldCharType'), 'begin') # sets attribute on element
instrText = OxmlElement('w:instrText')
instrText.set(qn('xml:space'), 'preserve') # sets attribute on element
instrText.text = 'TOC \o "1-3" \h \z \u' # change 1-3 depending on heading levels you need
fldChar2 = OxmlElement('w:fldChar')
fldChar2.set(qn('w:fldCharType'), 'separate')
fldChar3 = OxmlElement('w:t')
fldChar3.text = "Right-click …Run Code Online (Sandbox Code Playgroud) 如何更改Excel中CellValue的文本颜色?我可以更改单元格的前景色,但它会更改单元格内所有文本的颜色,这是我不想要的。我想仅突出显示单元格内的特定文本,即 CellValue 文本。
我使用下面的代码突出显示单元格文本,如何为 CellValue 完成此操作?
foreach (DocumentFormat.OpenXml.Spreadsheet.Cell currentCell in allCells)
{
Fill fill = new Fill()
{
PatternFill = new PatternFill
{
PatternType = PatternValues.Solid,
ForegroundColor = new ForegroundColor() { Rgb = "FFFF00" }
}
};
styleSheet.Fills.AppendChild(fill);
//Adding the CellFormat which uses the Fill element
CellFormats cellFormats = styleSheet.CellFormats;
CellFormat cf = new CellFormat();
cf.FillId = styleSheet.Fills.Count;
cellFormats.AppendChild(cf);
currentCell.StyleIndex = styleSheet.CellFormats.Count;
}
Run Code Online (Sandbox Code Playgroud)
我在 CellValue 中没有看到 Style 的任何属性
CellValue currentCellValue = currentCell.GetFirstChild<CellValue>();
if (currentCell.DataType == CellValues.SharedString) // cell has a …Run Code Online (Sandbox Code Playgroud) 我使用下面的代码来获取页数,但它没有给出实际页数(PFA)。获取总页数的更好方法是什么?
var pageCount = doc.ExtendedFilePropertiesPart.Properties.Pages.Text.Trim();
Run Code Online (Sandbox Code Playgroud)
注意:我们无法在我的 Azure Web 应用服务中使用 Office 主互操作程序集
提前致谢。
我对 python-docx 比较陌生。我试图更改现有文档中表格的行距,但它更改了文档中所有表格的行距。
这是一个最小的、可重现的示例,从头开始创建一个包含三个表的文档:
from docx import Document
from docx.shared import Inches
from docx.shared import Pt
from docx.enum.text import WD_LINE_SPACING
document = Document()
# Some sample text to add to tables
records = (
(3, '101', 'Spam'),
(7, '422', 'Eggs'),
(4, '631', 'Spam, spam, eggs, and spam')
)
# Create table 0
table = document.add_table(rows=1, cols=3)
hdr_cells = table.rows[0].cells
hdr_cells[0].text = 'Qty'
hdr_cells[1].text = 'Id'
hdr_cells[2].text = 'Desc'
for qty, id, desc in records:
row_cells = table.add_row().cells
row_cells[0].text = str(qty) …Run Code Online (Sandbox Code Playgroud) 如何以最快的方式使用ClosedXML库(从性能的角度来看)将值添加DataTable到现有的Excel工作表中?
注意:有方法可以使用DataTable参数创建新工作表,但主要问题是向现有工作表添加值.
openxml ×10
c# ×5
excel ×3
openxml-sdk ×2
python ×2
python-docx ×2
apache-poi ×1
css ×1
docx ×1
ms-word ×1
outlook ×1
outlook-2010 ×1