我正在努力创建具有从右到左表格的新文档。如何将表格方向设置为 RTL?
我尝试了以下代码,但它不起作用:
Table tb = new Table(new TableLayout() { Type = TableLayoutValues.Autofit });
tb.Append( new TableProperties(new TextDirection() { Val=TextDirectionValues.TopToBottomRightToLeft}, new RightToLeftText() { Val =new DocumentFormat.OpenXml.OnOffValue(true) }, new TableBorders(new TopBorder { Val = new DocumentFormat.OpenXml.EnumValue<BorderValues>(BorderValues.BasicThinLines), Size = 5 }, new BottomBorder { Val = new DocumentFormat.OpenXml.EnumValue<BorderValues>(BorderValues.BasicThinLines), Size = 5 }, new LeftBorder { Val = new DocumentFormat.OpenXml.EnumValue<BorderValues>(BorderValues.BasicThinLines), Size = 5 }, new RightBorder { Val = new DocumentFormat.OpenXml.EnumValue<BorderValues>(BorderValues.BasicThinLines), Size = 5 }, new InsideHorizontalBorder { Val = new DocumentFormat.OpenXml.EnumValue<BorderValues>(BorderValues.BasicThinLines), Size …Run Code Online (Sandbox Code Playgroud) 我使用 OpenXML 将 Datagridview 导出到 Excel。如果我使用 CellValues.String 导出单元格,则一切工作正常,Excel 文件中不会出现任何错误,但我需要的是将所有日期和数字数据正确转换为相应的单元格格式。我尝试使用内置格式(不是自定义格式)来更改单元格格式,但后来我的 Excel 损坏了。
这是我到目前为止所尝试的:
public void Export_to_Excel(DataGridView dgv, string path)
{
using (var workbook = SpreadsheetDocument.Create(path, SpreadsheetDocumentType.Workbook))
{
var workbookPart = workbook.AddWorkbookPart();
workbook.WorkbookPart.Workbook = new Workbook();
workbook.WorkbookPart.Workbook.Sheets = new Sheets();
var sheetPart = workbook.WorkbookPart.AddNewPart<WorksheetPart>();
var sheetData = new SheetData();
sheetPart.Worksheet = new Worksheet(sheetData);
Sheets sheets = workbook.WorkbookPart.Workbook.GetFirstChild<Sheets>();
string relationshipId = workbook.WorkbookPart.GetIdOfPart(sheetPart);
uint sheetId = 1;
if (sheets.Elements<Sheet>().Count() > 0)
{
sheetId =
sheets.Elements<Sheet>().Select(s => s.SheetId.Value).Max() + 1;
}
Sheet sheet = new …Run Code Online (Sandbox Code Playgroud) 我想用来从文件中Openxml抽象。我不知道该怎么做,并且在官方示例中没有找到任何有关它的示例。请帮我。"OLE package"".docx"
这是我的尝试:
\n我通过“MS Office 2016”构建了一个名为 的 Docx 文件"Test.docx",并将".zip"文件插入到"Test.docx". 我打开"Open XML SDK 2.5 Productivity Tool"Watch "Test.docx",找到了这个(图 1),但我没有获得任何有关如何通过反射代码提取此 zip 文件的信息。
然后我尝试使用 C# 并SharpCompress.dll提取该".zip"文件,接下来是代码:
class Program\n {\n static void Main(string[] args)\n {\n string filepath = @"C:\\Users\\\xe5\xae\x87\xe5\xae\x99\xe6\x97\xa0\xe6\x95\x8c\xe5\xb8\x85\xe5\xb0\x8f\xe4\xbc\x99\\Desktop\\test.docx";\n\n OleFileTest(filepath);\n }\n\n public static void OleFileTest(string filepath)\n {\n try\n {\n using (WordprocessingDocument Docx = WordprocessingDocument.Open(filepath, true))\n {\n Body body = Docx.MainDocumentPart.Document.Body;\n\n …Run Code Online (Sandbox Code Playgroud)这是一个带有子形状的 groupShape:
<p:nvgrpsppr>
<p:cnvpr name="Group 256" id="260" />
<p:cnvgrpsppr>
<a:grpsplocks nochangeaspect="1" />
</p:cnvgrpsppr>
<p:nvpr />
</p:nvgrpsppr>
<p:grpsppr bwmode="auto">
<a:xfrm>
<a:off y="1940518" x="2952779" />
<a:ext cy="2209679" cx="1219680" />
<a:choff y="1052" x="1972" />
<a:chext cy="1116" cx="616" />
</a:xfrm>
<a:solidfill>
<a:srgbclr val="F7B63E" />
</a:solidfill>
</p:grpsppr>
<p:sp>
<p:nvsppr>
<p:cnvpr name="Freeform 257" id="262" />
<p:cnvsppr>
<a:splocks noeditpoints="1" />
</p:cnvsppr>
<p:nvpr />
</p:nvsppr>
<p:sppr bwmode="auto">
<a:xfrm>
<a:off y="1160" x="2161" />
<a:ext cy="287" cx="288" />
</a:xfrm>
</p:sppr>
</p:sp>
Run Code Online (Sandbox Code Playgroud)
当我取消分组时,得到这个:
<p:grpsppr>
<a:xfrm>
<a:off y="0" x="0" />
<a:ext cy="0" …Run Code Online (Sandbox Code Playgroud) 我的应用程序是使用C#.net和开放式XML SDK(2.0)编写的.我使用开放的XML标签将段文件明智地分段并且明智地分段.但我找不到任何关于拆分单词文件页面的信息......
请求指导我摆脱这个问题.
我正在尝试在文档的中心生成一个带有图像的DocX文档,但我已经尝试了几样但没有任何结果.图像显示但位于左上角.addImageToBody函数来自MS网站(http://msdn.microsoft.com/en-us/library/office/bb497430(v=office.15).aspx).我试过使用HorizontalPosition类(http://msdn.microsoft.com/en-us/library/documentformat.openxml.drawing.wordprocessing.horizontalposition(v=office.14).aspx)但是没有工作为了我.
添加图片和通话功能:
MainDocumentPart mainPart = document.MainDocumentPart;
ImagePart imagePart = mainPart.AddImagePart(ImagePartType.Png);
using (FileStream stream = new FileStream(@"C:...\Logo.png", FileMode.Open))
{
imagePart.FeedData(stream);
}
AddImageToBody(document, mainPart.GetIdOfPart(imagePart));
Run Code Online (Sandbox Code Playgroud)
和功能:
private static void AddImageToBody(WordprocessingDocument wordDoc, string relationshipId)
{
int defX = 854;
int defY = 350;
int size = 3000;
// Define the reference of the image.
var element =
new DocumentFormat.OpenXml.Wordprocessing.Drawing(
new DW.Inline(
new DW.Extent() { Cx = defX * size, Cy = defY * size },
new DW.EffectExtent()
{
LeftEdge = …Run Code Online (Sandbox Code Playgroud) 我使用以下代码将xml(openxml)注入Word中的段落范围.问题是我收到一条错误消息,指出"无法将XML标记插入指定位置"
c#代码:
try
{
string oxml = ""; // this contains the xml listed below
// get the first paragraph
Paragraph p = this.Paragraphs[1];
object missing = Type.Missing;
// insert openxml formatted xml into paragraph range
p.Range.InsertXML(oxml, ref missing); // causes the exception
}
catch (Exception ex)
{
//_logger.Error("OpenXml Injection", ex);
}
Run Code Online (Sandbox Code Playgroud)
要注入的XML:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<?mso-application progid="Word.Document"?>
<pkg:package xmlns:pkg="http://schemas.microsoft.com/office/2006/xmlPackage" xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main">
<w:document xmlns:wpc="http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:m="http://schemas.openxmlformats.org/officeDocument/2006/math" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:wp14="http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing" xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing" xmlns:w10="urn:schemas-microsoft-com:office:word" xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main" xmlns:w14="http://schemas.microsoft.com/office/word/2010/wordml" xmlns:wpg="http://schemas.microsoft.com/office/word/2010/wordprocessingGroup" xmlns:wpi="http://schemas.microsoft.com/office/word/2010/wordprocessingInk" xmlns:wne="http://schemas.microsoft.com/office/word/2006/wordml" xmlns:wps="http://schemas.microsoft.com/office/word/2010/wordprocessingShape" mc:Ignorable="w14 wp14"> …Run Code Online (Sandbox Code Playgroud) 我正在使用Docx4j在swing应用程序中生成一个word文档.我想在标题中添加一个图片.文档已成功创建,但图片未显示.以下是应用程序的代码片段.我使用的是docx4j-nightly-20141016.jar文件.
import org.docx4j.wml.ObjectFactory;
public class WordDoc {
private WordprocessingMLPackage wordMLPackage;
private ObjectFactory factory;
private Hdr header;
public WordDoc() {
}
public void createWordDoc() throws Docx4JException, IOException, Exception {
wordMLPackage = WordprocessingMLPackage.createPackage();
factory = Context.getWmlObjectFactory();
Relationship relationship = createHeaderPart();
createHeaderReference(relationship);
wordMLPackage.getMainDocumentPart().addParagraphOfText("Hello Word!");
File file = new File("src/resources/images/logo.jpg");
byte[] bytes = convertImageToByteArray(file);
addImageInline(bytes);
wordMLPackage.save(new java.io.File("src/files/HelloWord14.docx"));
}
private Relationship createHeaderPart() throws InvalidFormatException {
HeaderPart headerPart = new HeaderPart();
headerPart.setPackage(wordMLPackage);
headerPart.setJaxbElement(createHeader("Text"));
return wordMLPackage.getMainDocumentPart().addTargetPart(headerPart);
}
private Hdr createHeader(String content) {
header = factory.createHdr(); …Run Code Online (Sandbox Code Playgroud) 我有一些docx文件。我使用OpenXML 2.5 SDK阅读它们,并TextInput在每个文档中搜索。
byte[] filebytes = System.IO.File.ReadAllBytes("Test.docx");
using (MemoryStream stream = new MemoryStream(filebytes))
using (WordprocessingDocument wordDocument = WordprocessingDocument.Open(stream, true))
{
IEnumerable<FormFieldData> fields = wordDocument.MainDocumentPart.Document.Descendants<FormFieldData>();
foreach (var field in fields)
{
IEnumerable<TextInput> textInputs = field.Descendants<TextInput>();
foreach (var ti in textInputs)
{
<<HERE>>
}
}
wordDocument.MainDocumentPart.Document.Save();
stream.Flush();
ETC...
}
Run Code Online (Sandbox Code Playgroud)
我如何在每个值中写入一个值TextInput?
谢谢!
最近,我发现自己需要将大型C#DataTable粘贴到Excel中,并且很高兴遇到SimpleOOXML(https://simpleooxml.codeplex.com)扩展的WorksheetWriter.PasteDataTable()函数,它确实做到了这一点。
不幸的是,它并没有像人们期望的那样自动将粘贴的DataTable转换为具有自动列宽和过滤功能的“表格格式”,而是只允许我指定单独的样式(例如边框,背景颜色等)。
如果有人知道如何使用SimpleOOXML(我在他们的论坛中找不到相关的东西),那将是惊人的,但是如果这不可能,我想知道是否可以使用传统的OpenXML来完成?
编辑
为了澄清起见,我检查了OpenXML的MSDN文档,但找不到执行以下操作的方法:
以编程方式使用OpenXML使用样式“ Table Style Light 9”将特定范围(G7:I9)格式化为表格,并保留现有的标题。