我创建了一个Word模板,然后通过OpenXML SDK处理该模板,用数据库查询中的数据替换文档的某些内容.
该模板由一些基本文本组成,其中纯文本内容控件注入了我想要替换文本的位置.然后我使用这些控件中的文本作为查找替换值的键.在大多数情况下,这工作正常(我只是更新Text对象的Text属性).
在一种情况下,我用表替换文本.在这种情况下,我在代码中构建一个表,然后用新的Table对象替换SdtContentRun对象的内容(Run对象的父对象,后者又是Text对象的父对象)...
var sdtContentRunElements =
from sdtContentRun in this.Document.MainDocumentPart.RootElement.Descendants<SdtContentRun>()
select sdtContentRun;
sdtContentRunElements.ForEach(sdtContentRunElement => {
Run firstRunElement = sdtContentRunElement.Descendants<Run>().FirstOrDefault();
if (firstRunElement != null) {
Text firstTextElement = firstRunElement.Descendants<Text>().FirstOrDefault();
if (firstTextElement != null) {
switch (firstTextElement.Text) {
case TableBookmark:
Table advisoryTable = new Table(...); // See below
OpenXmlElement parent = firstRunElement.Parent;
parent.RemoveAllChildren();
parent.Append(advisoryTable);
break;
case ContractorItemAdvisoriesLetter.ContractorCodeBookmark:
firstTextElement.Text = @"New text";
break;
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
}
这导致以下XML(取自用于Microsoft Office的Open XML SDK 2.0生产力工具)...
<w:sdtContent xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main">
<w:tbl>
<w:tr>
<w:tc>
<w:p>
<w:r>
<w:t>Lorem ipsum …
Run Code Online (Sandbox Code Playgroud) 我正在尝试编写继承自FMX TStyledControl的类.更新样式时,它会将样式资源对象加载到缓存中.
我使用自定义控件和测试FMX HD项目创建了包的项目组,如Delphi帮助中所述.安装包并将TsgSlideHost放在测试表单上后,我运行测试应用程序.它工作得很好,但是当我关闭它并尝试重建包时,RAD Studio会说"rtl160.bpl中的错误"或"指针操作无效".
看来在TsgStyledControl的LoadToCacheIfNeeded过程中有什么问题,但我不明白为什么.使用带有FMX样式的RTTI有什么限制吗?
TsgStyledControl来源:
unit SlideGUI.TsgStyledControl;
interface
uses
System.SysUtils, System.Classes, System.Types, FMX.Types, FMX.Layouts, FMX.Objects,
FMX.Effects, System.UITypes, FMX.Ani, System.Rtti, System.TypInfo;
type
TCachedAttribute = class(TCustomAttribute)
private
fStyleName: string;
public
constructor Create(const aStyleName: string);
property StyleName: string read fStyleName;
end;
TsgStyledControl = class(TStyledControl)
private
procedure CacheStyleObjects;
procedure LoadToCacheIfNeeded(aField: TRttiField);
protected
function FindStyleResourceAs<T: class>(const AStyleLookup: string): T;
function GetStyleName: string; virtual; abstract;
function GetStyleObject: TControl; override;
public
procedure ApplyStyle; override;
published
{ Published declarations }
end;
implementation
{ TsgStyledControl }
procedure …
Run Code Online (Sandbox Code Playgroud) 我在PostgreSQL中有一个名为customers的数据库,客户有一个名为CustomerInfo的表.CustomerInfo包含3个colunms ID,名称和地址.我想编写一个bash脚本来从CustomerInfo表中获取信息,但是一旦得到查询结果,我不知道如何访问各行.这是我写的脚本:
#!/bin/bash
results=`psql -d customers -c "select * from CustomerInfo where name = 'Dave'"`
echo $results['name']
Run Code Online (Sandbox Code Playgroud)
查询正确运行并返回正确的结果,但echo命令将只打印结果中的所有内容.我知道这不是正确的方法,有没有人知道将查询结果作为数组的方法,或者我只需编写自己的函数来解析结果?
谢谢!
可能的重复:
Java中的逻辑运算符
|之间有什么区别?和|| 在Java中?
如标题所述,我需要知道&
运算符和&&
运算符之间的区别。谁能用简单的话帮助我。
TMyPanel = class(TPanel)
public
procedure AfterConstruction; override;
end;
procedure TMyPanel.AfterConstruction;
begin
inherited AfterConstruction;
Caption := '';
end;
Run Code Online (Sandbox Code Playgroud)
我想在构造期间清除标题,但是这段代码不能像我期望的那样工作.它不会将标题设置为空字符串.如果我将''(空格)分配给Caption,它将保留,但这不是一个合适的解决方案.
我正在使用Delphi 2006.
delphi ×2
bash ×1
c# ×1
firemonkey ×1
if-statement ×1
java ×1
openxml ×1
openxml-sdk ×1
operators ×1
postgresql ×1
rtti ×1
sql ×1
vcl ×1
word-2010 ×1