I am trying to generate tables in reStructuredText. The content is the exported to pdf using rst2pdf. The content is coming from a database that I am parsing. As I don't know the column width in advance I am using the csv-table directive to facilite the table construction.
What I am currently struggling against is how to have cells which content can come on several lines. I tried the usual double quoted cells with a CR/LF but it does not work. Any idea ?
Here is my table with a not working two lines cell ("John, Junior" should come on two lines inside the cell):
.. csv-table:: a title
:header: "name", "firstname", "age"
:widths: 20, 20, 10
"Smith", "John", 40
"Smith", "John,
Junior", 20
any idea on how to progress ?
There is a solution proposed when using Sphinx here: csv-table formatting in Python docstrings (Sphinx) - multiple lines in one cell , but I am using rst2pdf where, as far as I can tell, I cannot change the theme as proposed above.
Thanks for your help.
Related
In R Markdown, to make a text bold, we just need to do:
**code**
The the word code shows in bold.
I was wondering if there is a way to create a new command, let's say:
***code***
That would make the text highlighted?
Thanks!
It is not easily possible to create new markup, but one can change the way existing markup commands are rendered. Text enclosed by three stars is interpreted as emphasized strong emphasis. So one has to change that interpretation and change it to something else. One way to do so is via pandoc Lua filters. We just have to match on pandoc's internal representation of emphasized strong text and convert it to whatever we want:
function Strong (strong)
-- if this contains only one element, and if that element
-- is emphasized text, convert it to highlighted text.
local element = #strong.content == 1 and strong.content[1]
if element and element.t == 'Emph' then
table.insert(element.content, 1, pandoc.RawInline('html', '<mark>'))
table.insert(element.content, pandoc.RawInline('html', '</mark>'))
return element.content
end
end
The above works for HTML output. One would have to define what "highlighted text" means for each targeted format.
See this and this question for other approaches to the problem, and for details of how to use the filter with R Markdown.
I'd like to have to have cells of a python notebook on 2 columns, for writng annotations next to code (for example, instead of inserting 2 cells below, I would insert I insert a cell on the right and a cell below on the left)
I know that it's possible to use custom css for changing the appearance (e.g https://github.com/nsonnad/base16-ipython-notebook/blob/master/ipython-3/output/base16-3024-dark.css ), is it possible also for the layout?
On the other hand, I found an example of how to use the css for creating a table layout (https://pixelsvsbytes.com/2012/02/this-css-layout-grid-is-no-holy-grail/), but not being very familiar with CSS I don't understand if this can be applied to an unknown number of equal blocks (unknown because they are generated interactively by the user). For reference, here is how currrently looks like:
You could just change the cells to markdown or raw and make them float right.
from IPython.core.display import HTML
HTML("<style> div.code_cell{width: 75%;float: left;}"
+"div.text_cell{width: 25%;float: right;}"
+"div.text_cell div.prompt {display: none;}</style>")
Now when you enter a cell and want it on the right press esc-r (or m).
esc- unselects it and allows the notebook to process commands. r is the command to make a raw cell.
I have several Wordpress HTML pages for import through CSV/excel. One of the fields is content for the Wordpress page. Since these pages are all the same except for in 3 places (2 names, 1 IMG URL) I'm trying to be efficient and upload an excel with custom fields.
What I'd like to do is merge the IMG urls and Product Names into the appropriate spot in the Excel cell text so it's imported as a complete page. I'm trying to avoid all the cutting and pasting when adding 100's of similar pages with only a few different spots.
Any tips or advice on where I can accomplish this? I haven't been able to figure it out or find help online.
Cell Data Example:
<div id="productimage" style="float:left;width:380px;">
<img alt="alternate" src="imagesource" />
</div>
<div id="productspecs" style="float:left;padding-left:25px;">
<h2><strong>Product Name</strong></h2>
</div>
"Product Name", "alternate", and "imagesource" I have fields for in a spreadsheet .. I just don't know how to merge them into this Cell Data Example to auto-populate these new pages.
Thanks!
If I understand your question correctly, you have html in an Excel cell and you want to make parts of that html dynamic by referencing content in other cells of the workbook.
I assume that in your example you want to make the imagesource and the Product Name dynamic.
You can copy and paste the html into the Excel formula editor. You can increase its height, so you see more than one line at a time. The formula editor can handle line breaks.
If you want to build a string that contains double quotes, you will need to use two double quotes if the quote is inside the string and three double quotes in a row if it is at the beginning or end of a string. You can use the ampersand to concatenate strings and cell references.
With your specific example above, the formula in Excel would read somewhere along these lines (replace Sheet2!A2 etc. with the cell that holds your data. Arrange that data in a table with a row for each product, then you can copy this formula down to get the desired result.
="<div id=""productimage"" style=""float:left;width:380px;"">
<img alt=""alternate"" src="""&Sheet2!A2&""" />
</div>
<div id=""productspecs"" style=""float:left;padding-left:25px;"">
<h2><strong>"&Sheet2!B2&"</strong></h2>
</div>"
Turn on "Wrap Text" in the cell format, otherwise you will see it all in one line of code. The screenshot below uses two rows of data with different texts for image source and product name in sheet 2.
EDIT: I tried to post this in a comment, but the double and triple quotes don't make it and get replaced with just one quote.
Also, you managed to delete some of the & signs that concatenate the different strings. Please look again at the original formula I've posted. Replace the cell references with yours, but don't mangle the code. The principle is this:
="First String"&A1&"Next String"
If the string has quotes inside, double them
="He said "Please" but nobody heard him"&A1&"next string"
If the string has quotes at the beginning of the string, then you need the opening quote for the string and the double quote for the quote inside the string. Likewise for quotes at the end of the string: duplicate the quote in the string and then add the closing quote.
="""Please" - he said"&A1&"and she answered "OK."""
I have a csv, and each line reads as follows:
"http://www.videourl.com/video,video title,video duration,thumbnail,<iframe src=""http://embed.videourl.com/video"" frameborder=0 width=510 height=400 scrolling=no> </iframe>,tag 1,tag 2",,,,,,,,,,,,,,,,,,,,,,,,,,
Is there a program I can use to clean this up? I'm trying to import it to wordpress and map it to current fields, but it isn't functioning properly. Any suggestions?
Just use search and replace in this case. remove the commas at the end and then replace the remaining commas with ",".
Should anyone else have the same issue. Know that this solution will only work with data much like the example giving. If data has a lot of text and there are commas within the text that need kept. Then search replacing comma will not work. Using regex would be the next option and that can be done in Notepad ++
However I think the regex pattern depends on the data so not much point creating an example.
PHP could be used to explode each line also. Remove values that match a regex out of many i.e. URL, money. Then what is left could be (depending on the data again) just a block of text. That approach may not work if there are two or more columns with a lot of text
I am generating an excel sheet with phpexcel, when using conditional formatting with the condition being (search for a text or part of it), i get a validation error when trying to open the generated sheet. Works perfectly with numbers, Less so WITH TEXTS.
Here is my code :
//conditional formatting
$objConditional1 = new PHPExcel_Style_Conditional();
$objConditional1->setConditionType(PHPExcel_Style_Conditional::CONDITION_CONTAINSTEXT)
->setOperatorType(PHPExcel_Style_Conditional::OPERATOR_CONTAINSTEXT)
->addCondition('X');
$objConditional1->getStyle()->getFont()->getColor()->setARGB(PHPExcel_Style_Color::COLOR_YELLOW);
$objConditional3 = new PHPExcel_Style_Conditional();
$objConditional3->setConditionType(PHPExcel_Style_Conditional::CONDITION_CELLIS)
->setOperatorType(PHPExcel_Style_Conditional::OPERATOR_GREATERTHANOREQUAL)
->addCondition('0');
$objConditional3->getStyle()->getFont()->getColor()->setARGB(PHPExcel_Style_Color::COLOR_GREEN);
$conditionalStyles = $objPHPExcel->getActiveSheet()->getStyle('B2')->getConditionalStyles();
array_push($conditionalStyles, $objConditional3);
array_push($conditionalStyles, $objConditional1);
$objPHPExcel->getActiveSheet()->getStyle('B2')->setConditionalStyles($conditionalStyles);
Does any one know how to work around this ? am i doing anything wrong ?
Thanks.
As far as i know, though i have not tested with your case specifically, when you try to apply conditional formatting based on CONTAINSTEXT,
you shouldn't call
'->addCondition('X')'
(line 5 in your code), but instead call the method:
->setText('X')
On your PHPExcel_Style_Conditional objects. This is how I specify the text to compare to in my PHPExcel sheets.