How to generate plain text reports with (fixed-width) tables - template-engine

I'm looking to easily define forms with fixed-width output. Most of my forms end up looking something like this:
[title]
text
some more text
A B CDE E
-------------------------------
1 2 text text
3 4.50 text text
some more text
With all output being plain text.
Since there are many different (and yet similar) forms, I'd like to use a templating engine with a simple interface for generating fixed-width textual tables. Are there engines which support easily creating such tables? Or perhaps other ways to generate such tables?

Related

Using Ruby, how to get the column types for a google sheet?

In a google sheet, different column could define different types, such as plain text, number or date. Using ruby, is there anyway to get these attributes?

Insert image into a csv column ruby

I'm currently doing a crawler for a website, and my goal is to have a CSV, with a name in the first column and an image the second one, which is inserted with a Ruby script using the CSV#open method.
I have already used this method but I don't know, and I don't find information about the problematic that is to insert an image into a column.
Is it really possible? If not, which functionality would you use to have a list with string + image after crawling?
A CSV (Comma Separated Values) file is a TEXT file which as the name implies has various values separated by commas, expressed using plain ASCII, or sometimes unicode. It is intended as a light weight way to transfer tabular data between different computer systems or programs. You can use it to spit out a table in a database, or the VALUES in something like a spreadsheet. The normal convention is for the first row(line) of the file to contain names or labels that represent what that column contains, and then data in the subsequent rows.
As such, there really is no practical way to embed an image within a CSV file. This is not a limitation of Ruby or Watir, but a limitation of textfiles which spans pretty much all languages and operating systems.
To do what you want you would be better off to save the images into a specific directory using unique filenames and insert those filenames into the CSV file.

Appropriate data structure to read this file

I have the following info in a text file.
Item Rate
pencil 2
eraser 1
laser 3
pencil 1
torch 4
eraser 1
Specifically, I want to know if any item in the above list has a different price.
For eg: In the above one, you can see that pencil has 2 rates ie 2 and 1.
The price of the eraser is same in both entries, so no problem.
Further complexities - The text file is very huge.
Since dicts don't allow us to store duplicate keys, please suggest ways to solve this problem along with appropriate data structure.
You Can use Hash Table with Separate Chaining Method.Hope it will works
Does the file have to be plain text ? I recommend tackling this problem by using XML format and parsing it with SAX (not DOM !). SAX will not load the entire file in the memory, so it works well with huge file sizes.
As for the data structure, you could always define your own or you could just use something like this Map<KeyType, List<ValueType>>. I feel it's counter-intuitive to have different prices mapped for the same product name. You could create a unique ID for every type of product and have a new field: quantity.

csv-table formatting through preamble?

Try as I might, I cannot figure out how to change the default table format in the pdf output from sphinx.
I could edit the .tex file, or the writer.py source code... but both of those seem like bad options.
Is there any thing that can be passed to the preamble to accomplish that?
Depending on what you are trying to accomplish by changing the table format. For instance if you want to define row colors and change the tables accordingly across the document you can use both the xcolor package and redefine how tabular handles that at the point of definition by changing the tabular environment.
So in the preamble you would do
\usepackage[table]{xcolor}
\definecolor{foo}{RGB}{236,137,29}
\definecolor{bar}{RGB}{232,108,31}
\let\newtabular\tabular
\let\newendtabular\endtabular
\renewenvironment{tabular}{\rowcolors{2}{foo}{bar}\newtabular}{\newendtabular}
This will overwrite the default tabular environment and apply the foo and bar row colors throughout the document, starting at the second row.
For having more directives related to tables. You should take a look at sphinxtr
Jeff Terrace has some great extensions included, but the two main ones to use are numfig and figtable. You can wrap a csv table into figtable.
.. figtable::
:label: my-csv-label
:caption: My CSV Table
:nofig:
.. csv-table::
:file: data/foo.csv
:header-rows: 1
Changing the standard table format with the caption below instead of above. Then you also have the added benefit of being able to directly link to that table by using :num:.
:num:`Table #my-csv-label`
It will automatically number accordingly, without referencing the label name. You can also use
.. figtable::
:spec: {r l r l}
To better define how you want your table to appear.

Convert ascii files into normal human-readable file

I have got ASCII files and want to convert them into maybe excel or tab/csv delimited text file. The file is a table with field name and field attributes. It also includes index name, table name and field(s) to index if required depending on the software. I don't think it is necessary to think of this. Well, field name and field attributes are enough, I hope so. I just want the information hidden inside. Can you all experts help me to get this done.
The lines are something like this:
10000001$"WORD" WORD$10001890$$$$495.7$$$N$$
10000002$11-word-word word$10000002$$$$$$$Y$$
10000003$11-word word word$10033315$0413004$$$$$$N$$
10000004$11-word word word$10033315$$$$$$$Y$017701$
The general answer, before knowing your ascii file in details, operating system, and so on, would be:
1 - cut the top n-lines, that containg the information you don't want. Leave the filds names, if you want to.
2 - check if the fields are separated by a common character, for example, one comma ,
3 - import the file inside a spreadsheet program, like Excel or OpenOffice Calc. In OOCalc, choose to import the file, then select the correct separating character
that's all.

Resources