将星期几转换为数字

将星期几转换为数字

纺织制造商,

我如何将文件内容的星期几更改为显示数字:

星期一 = 2,星期二 = 3...星期六 = 7,星期日 = 1

我的代码

\documentclass{article}
\usepackage{filecontents}
\begin{filecontents*}{file.tex}
%Type =1,2...10
No,Dayofweek,Name
1,Monday,A
2,Tuesday,B
3,Wednesday,D
30,Thursday,C
31,Friday,M
131,Saturday,N
132,Sunday,K

\end{filecontents*}

\usepackage{datatool}

\DTLloaddb[autokeys=false]{file}{file.tex}

\begin{document}
Display Dayofweek => Number 

\DTLforeach*
    {file}% Database
    {\No=No,\Dayofweek=Dayofweek,\Name=Name}{%
    \noindent\Dayofweek \quad \Name\par

  }% 

\end{document}

在此处输入图片描述

答案1

如果我正确理解了这个问题......

\documentclass{article}
\usepackage{filecontents}
\begin{filecontents*}{file.tex}
%Type =1,2...10
No,Dayofweek,Name
1,Monday,A
2,Tuesday,B
3,Wednesday,D
30,Thursday,C
31,Friday,M
131,Saturday,N
132,Sunday,K

\end{filecontents*}
\usepackage{datatool}
\DTLloaddb[autokeys=false]{file}{file.tex}
\newcommand\Sundaycode{1}
\newcommand\Mondaycode{2}
\newcommand\Tuesdaycode{3}
\newcommand\Wednesdaycode{4}
\newcommand\Thursdaycode{5}
\newcommand\Fridaycode{6}
\newcommand\Saturdaycode{7}
\newcommand\daycode[1]{\csname #1code\endcsname}
\begin{document}
Display Dayofweek $=>$ Number 

\DTLforeach*
    {file}% Database
    {\No=No,\Dayofweek=Dayofweek,\Name=Name}{%
    \noindent\daycode{\Dayofweek} \quad \Name\par

  }% 
\end{document}

在此处输入图片描述

相关内容