Using DocX I need to do something like this:
A long
text description.
Except I need the "1." to be a paragraph and the "A long text description" to be a paragraph. I cannot use a list for this.
late answer, but use a 2 column table with no visible borders
some code i hacked out of my current thing. this makes a table and populates the cells with the contents of my cells,
you'd just need to make a table, with 2 columns. and then iterate build a row with with cell[0] for the numeral, and cell[1] for the sentence
doc.InsertParagraph("Table Title: " + (component).SubTitle, false, SubtitleStyle);
var table = doc.AddTable(component.ColumnCount, component.RowCount);
int rowcount = 0;
foreach (DataCell datacell in component.TableData)
{
table.Rows[rowcount].Cells[0].Paragraphs.First().Append(rowcount+1);
table.Rows[rowcount].Cells[1].Paragraphs.First().Append(datacell.CellValue);
rowcount++;
}
doc.InsertTable(table);
Related
Is there any way to get a hover tool tip working on a shiny data table that has some information, this is possible on graphs but never seen it done before on a data table
Yes, like this (no need of Shiny):
library(DT)
datatable(head(iris),
options=list(initComplete = JS(c(
"function(settings){",
" var table = settings.oInstance.api();",
" var cell = table.cell(2,2);",
" cell.node().setAttribute('title', 'TOOLTIP CONTENTS');",
"}")))
)
table.cell(2,2) means the cell at row 2 and column 2; indices start at 0 in Javascript, and the column of row names is taken into account.
I have a .docx template with an empty table, where I am adding values:
def manipulate_table():
table = doc.tables[0]
table.cell(0, 0).text = 'A'
table.cell(0, 1).text = 'B'
table.cell(0, 2).text = 'C'
table.cell(0, 3).text = 'D'
After adding these values, the the table attribute "Centered" is gone, which is standard behaviour.
How can I loop through my table and center all values again? I've already Googled, but found nothing helpful. E.g.: does not work:
for cell in ....????:
tc = cell._tc
tcPr = tc.get_or_add_tcPr()
tcVAlign = OxmlElement('w:vAlign')
tcVAlign.set(qn('w:val'), "center")
tcPr.append(tcVAlign)
I appreciate all your help.
The .text property on a cell completely replaces the text in the cell, including the paragraph(s) that were there before.
The "centered" attribute is on each paragraph, not on the cell. So you need to do something like:
from docx.enum.text import WD_ALIGN_PARAGRAPH
cell.paragraphs[0].alignment = WD_ALIGN_PARAGRAPH.CENTER
to each of the "new" paragraphs (assigning to .text will leave you with exactly one in each cell).
So I am going off memory here because I cannot see the code I am trying to figure this out for at the moment, but I am working with some old VB Script code where there is a data connection that is set like this:
set objCommand = Server.CreateObject("ADODB.command")
and I have a field from the database that is being stored in a variable like this:
Items = RsData(“Item”).
This specific field in the database is a long string of
text:
(i.e. “This is part of a string of text…Header One: Here is text after header one… Header Two: Here is more text after header two”).
There are certain parts of the text that I wish to store as a variable that are between two index positions in the long string of text within that field. They are separated by headers that are stored in the text field above like this: “Header One:” and “Header Two:”, and I want to capture all text that occurs in between those two headers of text and store them into their own variable (i.e. “Here is text after header one…”).
How do I achieve this? I have tried to use the InStr method to set the index but from how I understand how this works it will only count the beginning of where a specific part of the string occurs. Am I wrong in my thinking of this? Since that is the case, I am also having trouble getting the Mid function to work. Can some one please show me an example of how this is supposed to work? Remember, I am only going off of memory so please forgive me that I am unable to provide better code examples now. I hope my question makes sense!
I am hopeful that someone can help me with an answer tonight so I can try this out tomorrow when I am near the code again! Thank you for your efforts and any help offered!
You can extract all the substrings starting with the text Header and ending just before either the next Header or end-of-string. I have used regular expression to implement that and it is working for me. Have a look at the code below. If I get a simpler(non-regex solution), I will update the answer.
Code:
strTest = "Header One: Some random text Header Two: Some more text Header One: Some random textwerwerwefvxcf234234 Header Three: Some more t2345fsdfext Header Four: Some randsdfsdf3w42343om text Header Five: Some more text 123213"
set objReg = new Regexp
objReg.Global = true
objReg.IgnoreCase = false
objReg.pattern = "Header[^:]+:([\s\S]*?)(?=Header|$)" '<---Regex Pattern. Explained later.
set objMatches = objReg.Execute(strTest)
Dim arrHeaderValues() '<-----This array contains all the required values
i=-1
for each objMatch in objMatches
i = i+1
Redim Preserve arrHeaderValues(i)
arrHeaderValues(i) = objMatch.subMatches.item(0) '<---item(0) indicates the 1st group of each match
next
'Displaying the array values
for i=0 to ubound(arrHeaderValues)
msgbox arrHeaderValues(i)
next
set objReg = Nothing
Regex Explanation:
Header - matches Header literally
[^:]+: - matches 1+ occurrences of any character that is not a :. This is then followed by matching a :. So far, keeping the above 2 points in mind, we have matched strings like Header One:, Header Two:, Header blabla123: etc. Now, whatever comes after this match is relevant to us. So we will capture that inside a Group as shown in the next breakup.
([\s\S]*?)(?=Header|$) - matches and captures everything(including newlines) until either the next Header or the end-of-the-string(represented by $)
([\s\S]*?) - matches 0+ occurrences of any character and capture the whole match in Group 1
(?=Header|$) - match and capture the above thing until another instance of the string Header or end of the string
Click for Regex Demo
Alternative Solution(non-regex):
strTest = "Header One: Some random text Header Two: Some more text Header One: Some random textwerwerwefvxcf234234 Header Three: Some more t2345fsdfext Header Four: Some randsdfsdf3w42343om text Header Five: Some more text 123213"
arrTemp = split(strTest,"Header") 'Split using the text Header
j=-1
Dim arrHeaderValues()
for i=0 to ubound(arrTemp)
strTemp = arrTemp(i)
intTemp = instr(1,strTemp,":") 'Find the position of : in each array value
if(intTemp>0) then
j = j+1
Redim preserve arrHeaderValues(j)
arrHeaderValues(j) = mid(strTemp,intTemp+1) 'Store the desired value in array
end if
next
'Displaying the array values
for i=0 to ubound(arrHeaderValues)
msgbox arrHeaderValues(i)
next
If you don't want to store the values in an array, you can use Execute statement to create variables with different names during run-time and store the values in them. See this and this for reference.
I have three part in my PDF generating document using iTextSharp library.
The Header and footer I am printing using OnEndPage() of PdfPageEventHelper class. The header and footer printing well in all pages.But problem in printing large table content from middle of the page.
Now, I am facing problem when I have more that 100 table rows content to print on middle of the page.
On first page (middle of the page) I am printing table with more than 100 rows, but in this case it leave the first page empty and start printing table content on second page. Here is my table that I am trying to print on first page
PdfPTable table = new PdfPTable(5);
table.HeaderRows = 1;
table.SplitLate = false;
table.SplitRows = false;
table.SetTotalWidth(new float[] { 100, 75, 75, 75, 75 });
table.LockedWidth = true;
for (int i = 0; i < 150; i++)
{
PdfPCell cell = new PdfPCell(new phrase());
cell.Colspan = 5;
table.AddCell(cell);
}
I am using iTextSharp version: 5.4.5.0
Is there any configuration need to do, that will prevent page break?
But I am getting actual result in this format
Allow me to comment on these two lines:
table.SplitLate = false;
table.SplitRows = false;
The first line tells iTextSharp what it should do if a row doesn't fit a page. If you set this value to false, rows will be split late. For instance: you have a big row that doesn't fit the current page. In that case, the row will be forwarded to the next page. If it still doesn't fit the page, then another decision needs to be made: should the row be split or not?
The second line gives iTextSharp the answer to that question. If the value of SplitRows is true, then the row will be split. If the value is false, the row will be dropped. Allow me to quote the official documentation (p115 of "iText in Action - Second Edition"):
Ths is a dangerous line, because now not one row will be split. Rows that are too high to fit on a page will be dropped from the table!
I have the feeling that you want all the rows to show up in the table, so I suggest that you change the two lines I mentioned to:
table.SplitLate = true;
table.SplitRows = true;
Actually: why don't you just remove those two lines? The default value of SplitLate and of SplitRows is true.
Same thing happened to me using nested tables.
I solved this problem using .SplitLate = false; in the first table :)
Am designing simple report in Devexpress. I add three labels continuously in xtrareport. 1st label & last label are set in designer screen but middle label data comes from database it may be (big or small) word or sentence. If data comes from database big means 3rd label get overlap with this data. How to solve this ?? Thanks in advance.
0. Three labels.
In report designer set the width of you 2nd label as more as possible:
Set the CanShrink, CanGrow, Multiline and WordWrap to true:
xrLabel2.CanShrink = true;
xrLabel2.CanGrow = true;
xrLabel2.Multiline = true;
xrLabel2.WordWrap = true;
In result you will get something like this:
1. One label with special format.
You can use one label with format string. Use {0} as placeholder for your data source values:
xrLabel1.DataBindings.Add(new XRBinding("Text", null, "Value", "Here is the text: «{0}». Here is the end."));
Also you can set the CanShrink, CanGrow, Multiline and WordWrap to true.
The result will be something like this:
2. One label with [brackets] in the labels's text.
You can insert a data field name with [brackets] into the control's text. For example:
xrLabel1.Text = "Here is the text: «[Value]». Here is the end."
And here is the result: