Graphics, Figures & TablesImporting Data from CSV file to Latex Table

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
sw3quant
Posts: 76
Joined: Tue Nov 02, 2010 11:40 pm

Importing Data from CSV file to Latex Table

Post by sw3quant »

I am running WinEdt 9.0, MikTex 2.9 on windows 7 pro.

I am constructing a standard format PDF report and must follow that format (ie the table is in a particular format with colors and fonts etc etc). The format requires large tables to be populated with float data points which are held in a CSV file on my PC. This process is going to be automated eventually. There seems to be a number of ways of doing this but i am not sure which is the simplest. Ideally I would like to be able to "index into" myFile.txt eg x= load(myFile.txt), val1 = x(3,17); etc

How do I assign values from "myFile.txt" to my variables val1, val2, val3, val4?

thank you!

Code: Select all

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{caption}
\usepackage{float}
\usepackage{xspace}
\usepackage{verbatim}
\usepackage{array}
\usepackage{multirow}
\usepackage{hhline}
\usepackage{ifthen}
%http://www.tug.org/texmf-dist/doc/latex/pgfplots/pgfplotstable.pdf

\newread\file
\openin\file=A:/myReports/latestResults/myFile.txt
\loop\unless\ifeof\file
    \read\file to\fileline % Reads a line of the file into \fileline
    % Do something with \fileline
\repeat
\closein\file


\begin{tabular}{|c|c|c|}
  \hline
  t1 & t2 & t3 \\
  y1 & val1 & val4 \\
  y2 & val2 & val3 \\
  \hline
\end{tabular}


\end{document}


Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org
LaTeX Beginner's Guide LaTeX Cookbook LaTeX TikZ graphics TikZによるLaTeXグラフィックス
Post Reply