totravel / minidocx

Fast and easy to use C++ library that creates or modifies Microsoft Word files without installing Word.
MIT License
83 stars 26 forks source link

请问如何输入 tab 控制符 #17

Open jdhanyang opened 7 months ago

jdhanyang commented 7 months ago

输入 tab 是用来对齐用的,代码如下:

auto p = doc.AppendParagraph("甲 方:\t\t\t\t乙 方:", 12, "Times New Roman", "宋体");

以上的 \t 并不起作用,生成的文件中被替换成了空格,请教应如何输入 tab 控制符

GermanAizek commented 7 months ago

输入 tab 是用来对齐用的,代码如下:

auto p = doc.AppendParagraph("甲 方:\t\t\t\t乙 方:", 12, "Times New Roman", "宋体");

以上的 \t 并不起作用,生成的文件中被替换成了空格,请教应如何输入 tab 控制符

@jdhanyang, have you tried to do this? Its only and higher C++11 feature.

auto p = doc.AppendParagraph(R"(甲 方:\t\t\t\t乙 方:)", 12, "Times New Roman", "宋体");
jdhanyang commented 7 months ago

@GermanAizek
Thanks, but it doesn't work.

auto p = doc.AppendParagraph(R"(甲 方:\t\t\t\t乙 方:)", 12, "Times New Roman", "宋体");

result is: 甲 方:\t\t\t\t乙 方:

Microsoft Visual Studio Community 2022 (64 位) , ISO C++14 标准 (/std:c++14)

totravel commented 7 months ago

try this:

auto r = doc.AppendParagraph().AppendRun();
r.AppendText(u8"甲方:");
r.AppendTabs(4);
r.AppendText(u8"乙方:");