![將星期轉換為數字](https://rvso.com/image/392355/%E5%B0%87%E6%98%9F%E6%9C%9F%E8%BD%89%E6%8F%9B%E7%82%BA%E6%95%B8%E5%AD%97.png)
紡織製造商,
我如何將文件內容的星期幾更改為顯示編號:
星期一 = 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}