我正在寻找使用的示例mailmerge
编写求职信的软件包,在电子表格上填写姓名和地址。该软件包附带一个示例,但您必须手动输入所有数据。
答案1
我用datatool
包。我不使用letter
文档类,因为我使用自己的信头包加上article
类。但如何做到这一点的基本知识应该很清楚,并且适用于letter
类。检查地址行中的空字段很重要,否则您将得到空白行。
我使用parskip
带有字母的包,它将设置\parindent
为 0 并使用空行分隔段落。如果您不喜欢这样,那么您可能希望在环境中设置地址行{tabular}{@{}l}
。
\documentclass{article}
\usepackage{datatool}
\usepackage{parskip}
\makeatletter
% Blank/missing fields commands
% \skipblank adds \\ to filled field; * version adds \space instead of newline
\newcommand\skipblank{\@ifstar\@spskip\@nlskip}
\newcommand\@nlskip[1]{\ifthenelse{\DTLiseq{#1}{}}{\relax}{#1\\}}
\newcommand\@spskip[1]{\ifthenelse{\DTLiseq{#1}{}}{\relax}{#1\space}}
% \checkblank replaces blank fields with ***
\newcommand\checkblank[1]{\ifthenelse{\DTLiseq{#1}{}}{***}{#1}}
\makeatother
\begin{document}
\DTLloaddb{addresses}{mail-merge-addresses.csv} % use your actual address database here
\DTLforeach*{addresses}{%
\addtitle=Title,
\firstname=FirstName,
\lastname=LastName,
\position=Position,
\addressi=Address1,
\addressii=Address2,
\addressiii=Address3,
\city=City,
\state=State,
\zip=Zip,
\country=Country}
{%
\setcounter{page}{1}
\thispagestyle{empty}
\checkblank{\addtitle}\ \firstname\ \lastname,\\
\skipblank{\position}
\skipblank{\addressi}
\skipblank{\addressii}
\skipblank{\addressiii}
\city, \state\ \zip\\
\skipblank*{\country}
Dear \checkblank{\addtitle}\ \lastname:
This is the text of the letter.
Sincerely,
\clearpage
}
\end{document}
该mail-merge-addresses.csv
文件如下:(它故意有空白字段来说明字段检查。)
Title, LastName, FirstName, Position, Address1, Address2, Address3, City, State, Zip, Country
Dr., Smith, James, Chair, Dept. of Physics, University of Somewhere, 434 East Hall, Cambridge, MA, 02139,
Mr., Jones, Bill, Director of Human Resources, , University of Nowhere, A203 King St., Stanford, CA, 94305,
, Brown, Sally, , Firstline, , 3rdline, East Lansing, MI, , USA