Sphinx: include xlsx data into rst - python-sphinx

What I want is to include an xlsx sheet (or rather the data of said file) into Sphinx documentation.
Is there any way to convert an xlsx sheet to restructuredText?

You do not need to convert it to rst. If you export your xlsx sheet to a comma separated file (csv) you can then use the csv-table directive.
The great thing is that you need to set up your table in your csv only once, and whenever you update your xlsx sheet, just export again to csv to the same location of where your table was before.
.. csv-table:: The contents of my xlsx sheet exported to mytable.csv
:widths: 15 40 20
:header: "Header 1", "Header 2", "Header 3"
:file: mytable.csv
That is all. Add as many widths and headers as you have columns in your file.
Note that in the documentation a security warning is given when using the :file: option. You can choose to copy paste the comma separated text into the document. However, if you update the table regularly I find it easiest to just export again to csv.

I have just released sphinxcontrib-excel, which embeds xlsx, xls and ods data (without style, font, charts) into your sphinx documentation. And you do not need to convert from xlsx to csv because the library does it for it.
Here is an example page where it was used to render excel data in readthedocs.org directly.

Related

How do I wrap data in BIRT?

I have developed a BIRT report and need to export the output as PDF and as an Excel Spreadsheet. I am looking a solution to wrap data in PDF report exported from BIRT. A text gets truncated in the PDF, if it does not have spaces as soon as it exceeds the available width of the column.
e.g. phone number getting truncated
I would like to know if there is a solution without the need for adding a custom code as provided in How to wrap column data in birt report. This solution adds whitespace to the data which is not desirable when the report is exported to an excel spreadsheet. In essence, this solution manipulates the data which isn't the right thing to do.
I have tried using the Whitespace auto option but that does not work.
I am using BIRT version 4.12.
I was able to figure out the solution for getting the text wrapped in the PDF export. Made use of IPDFRenderOption.PDF_WORDBREAK for the same.
PDFRenderOption pdfOptions = new PDFRenderOption();
pdfOptions.setOutputFileName("T:/temp/filename.pdf");
pdfOptions.setOutputFormat("pdf");
pdfOptions.setOption(IPDFRenderOption.PDF_WORDBREAK, true);
task.setRenderOption(pdfOptions);
task.run();

Importing data from excel files in D3 js

I am working on D3 js collapsible tree layout, i want to know is there any way we can directly feed the data from excel file rather than using json object file?
D3.js doesn’t have built-in Excel file format parser. It does, however, have a CSV format data parser. You can save your worksheet as CSV and use the resulting text as a source for the D3.js visualization.

Indesign data merge on 2 pages with different layout

I would like to have a two page Indesign document. First page has text + image and second page has 2 images. The images should come from a csv file that gets data merged with the Indesign document. Is this achievable. I have only been able to do a data merge when I have one page, but then all pages have the same layout. Is this possible and how do I do it? Thanks.
The solution is to work with XML files (File -> Import XML) instead of CSV. You can make any type of document and put XML objects in text fields, images, ... XML is much more flexible than CSV.
a CSV field that is named #photo1 will link to a file location
column F (for instance)
#photo1
c:\foldername\filename.jpg
c:\folder2name\subfolder\otherfile.png
f:\file3.tiff

Visual Studio: Use csv file for "Find Text" validation in web performance test

I can use csv files to enter data into input field after a test is recorded. I was wondering if csv file could be used for "Find Text" validation field. I don't see options to add csv file so I have directly hardcode text be checked. If I could add a csv file then I would just need to change the csv file once the website texts are changed. Could this be done by using codedUI test?
Thank you
The fields of a data source can be used in many places within a Web Performance Test. There are two main ways.
In the properties panel for the call of the validation rule, click in the value field for the required property. You should get a box allowing the data source field to be chosen.
Alternatively enter text similar to the following into the field
{{DataSource1.YourFileName#csv.FieldName}}
Note the doubled curly braces {{ and }} around the full data source string. You can also add extra text to this sort of entry, eg
Some text{{DataSource1.YourFileName#csv.FieldName}}and even more text

How to edit tab in .xls with Spreadsheet gem?

I am trying to open an existing .xls file and overwrite the contents in one spreadsheet (tab).There are many tabs on the file and many have pivottables and other visual presentations.
I have tried Spreadsheet and axlsx. Axlsx has great controls but overwrites the entire file including any other created tabs. Spreadsheet will open and edit a file but you have to copy the other tabs which will remove the excel formatting.
Is there a way to use Ruby to add data to only one tab in a spreadsheet without changing content in the other tabs?
Update:
Here is what I am testing now using the Spreadsheet gem. I can open a spreadsheet that has multiple tabs where one tab contains a pivottable, another contains a chart, and another the raw data. They have to be saved out as a new doc otherwise you get a File Format is not Valid error.
open_book = Spreadsheet.open('../data/exports/test_output_dashboard.xls')
puts "#{open_book.worksheet(0)}"
puts "#{open_book.worksheet(1)}"
puts "#{open_book.worksheet(2)}"
open_book.write('../data/exports/test_output_dashboard_2.xls')
If I just open and resave the new document is fine, a working copy of the original. However, if I edit the tab with the raw data as in this code then when I open the file it is shown as needs to be 'repaired' and none of the tabs show the correct information.
open_book = Spreadsheet.open('../data/exports/test_output_dashboard.xls')
puts "#{open_book.worksheet(0)}"
puts "#{open_book.worksheet(1)}"
puts "#{open_book.worksheet(2)}"
new_row_index = open_book.worksheet(1).last_row_index + 1
open_book.worksheet(1).insert_row(new_row_index, row_2)
open_book.write('../data/exports/test_output_dashboard_4.xls')
Any suggestions for adding data to one tab of an excel doc while keeping the other tabs intact would be greatly appreciated. The solution can be any gem or could be any language or automatable tool.
UPDATE:
Here is an example Excel dashboard that I am using for testing. I am writing rows into the data tab. https://dl.dropboxusercontent.com/u/23226147/test_output_dashboard.xlsx
UPDATE:
With RubyXL I can open and inspect the content of each tab but the saved doc cannot be opened by Excel.
workbook = RubyXL::Parser.parse("../data/exports/test_output_dashboard.xlsx")
puts "#{workbook.worksheets[0].inspect}"
puts "#{workbook.worksheets[1].inspect}"
puts "#{workbook.worksheets[2].inspect}"
workbook.write("../data/exports/test_output_dashboard_5.xlsx")
If you're just looking for a quick tool, RubyXL might do the trick for you:
https://github.com/weshatheleopard/rubyXL
It parses existing .xlsx .xlsm files and has a decent set of documentation.
You could try cloudxls.com API. You can merge data into existing xls and xlsx files using its API. If that is not an option, you most likely have to use some java libraries like Apache POI.
Solution for Windows users only.
I use to modify Excel spreadhseet with the gem win32ole and it works fine.
In case it is interesting for you here is a short sample to open a file and activate a given tab:
excel = WIN32OLE.new('Excel.Application')
excel.visible = true
filepath = 'e:\tmp\file.xlsx'
cur_book = excel.workbooks.Open(filepath)
sheet_name = 'sheet1'
cur_sheet = cur_book.Worksheets(sheet_name)
# put value 10 in Cell(2,2)
cur_sheet.Cells(2,2).Value = 10
Official documentation: http://ruby-doc.org/stdlib-1.9.3/libdoc/win32ole/rdoc/WIN32OLE.html

Resources