In my iTextsharp Pdf program, I need to truncate the text which goes beyond the width of the table cell. Actually it does wordwrap the content to the next line. Pl help provide the solution to do the same.
Code
string Value = "This is very Long Text Value";
var cellContent = new Phrase();
cellContent.Add(new Paragraph(Value, fontHeader));
cellContent.Add(new Paragraph("\n"));
Related
I have a Matlab listbox on which some strings are very long. I do not want to make listbox too wide just only because of these few long strings.
Is there anyway to display trailing edge of these long strings in my listbox by simply hovering the mouse over those strings without using scroll pane?
Perhaps, you can set the TooltipString property of your listbox. This is what is displayed when you hover the cursor on some object. It will not be a nice or user friendly but is better than nothing.
%Create a listbox
myListbox = uicontrol('Style','listbox');
set(myListbox,'TooltipString','','Callback',#listboxCB);
%Callback function called each time the listbox value is changed
%It should also be called whenever the 'String' property is updated
function listboxCB(obj,evt)
%Get the value
v=get(obj,'Value');
if isempty(v)
set(myListbox,'TooltipString','');
return;
end
%Get the string corresponding to that line
str = get(obj,'String');
str = str{v(1)}; %Show the first one (if 'multiselect' = 'on')
set(myListbox,'TooltipString',str);
end
There may be some clever way by interacting directly with the underlying Java objects.
See Jan's answer using Java objects. Worked great.
% Prepare the Matlab listbox uicontrol
hFig = figure;
listItems = {'apple','orange','banana','lemon','cherry','pear','melon'};
hListbox = uicontrol(hFig, 'style','listbox', 'pos',[20,20,60,60], 'string',listItems);
% Get the listbox's underlying Java control
jScrollPane = findjobj(hListbox);
% We got the scrollpane container - get its actual contained listbox control
jListbox = jScrollPane.getViewport.getComponent(0);
% Convert to a callback-able reference handle
jListbox = handle(jListbox, 'CallbackProperties');
% Set the mouse-movement event callback
set(jListbox, 'MouseMovedCallback', {#mouseMovedCallback,hListbox});
% Mouse-movement callback
function mouseMovedCallback(jListbox, jEventData, hListbox)
% Get the currently-hovered list-item
mousePos = java.awt.Point(jEventData.getX, jEventData.getY);
hoverIndex = jListbox.locationToIndex(mousePos) + 1;
listValues = get(hListbox,'string');
hoverValue = listValues{hoverIndex};
% Modify the tooltip based on the hovered item
msgStr = sprintf('<html>item #%d: <b>%s</b></html>', hoverIndex, hoverValue);
set(hListbox, 'Tooltip',msgStr);
end % mouseMovedCallback
https://www.mathworks.com/matlabcentral/answers/436048-display-trailing-edge-of-a-long-strings-of-a-listbox-by-hovering-the-mouse-over-the-string#answer_352806
Can anyone tell how can change font size of entire word application using spire.doc?
How to select the entire text range and change the font size and style?
Can anyone please help me??
in Vb .net :
Dim document As New Document()
document.LoadFromFile("test.html", FileFormat.Html, XHTMLValidationType.None)
For Each section As Section In document.Sections
For Each paragraph As Paragraph In section.Paragraphs
For Each docObject As DocumentObject In paragraph.ChildObjects
If docObject.DocumentObjectType = DocumentObjectType.TextRange Then
Dim text As TextRange = TryCast(docObject, TextRange)
text.CharacterFormat.FontName = "Calibri"
End If
Next docObject
Next paragraph
Next section
document.SaveToFile("HtmlFileToPDF.pdf", FileFormat.PDF)
I am trying to export a report to excel. When I export my report to Excel I am getting blank rows between each detail section. I assume this is because I have a context menu in form of a normal text element which overlies the "normal" text elements.
Does anybody have any advice on how I can stop the blank rows occurring? Is it possible to suppress a text element only when it is exported to Excel?
Thanks!
Try to make it compact.
It should be no space between each object. You should set every object on the same row has the same height and every object on column has the same width.
When there's a space between objects, it will create a cell on excel.
There are 2 articles from Ken Hamady that might be helpfull:
http://kenhamady.com/cru/archives/231
http://www.kenhamady.com/news0506.shtml (scroll to the bottom of the page)
Another option , if you are working with tabular data is to use a report extension like it is shown in this video: https://www.youtube.com/watch?v=3hk6FJ1dvb4
This approach will use the Crystal report as a datasource and will export the data from a grid with much better formatting. The video is using a 3rd party tool, but it is free - http://www.r-tag.com/Pages/CommunityEdition.aspx
Use This Code:
Public Shared Sub ExportDataSetToExcel(ByVal ds As DataTable, ByVal filename As String)
Dim response As HttpResponse = HttpContext.Current.Response
response.Clear()
response.Buffer = True
response.Charset = ""
response.ContentType = "application/vnd.ms-excel"
Using sw As New StringWriter()
Using htw As New HtmlTextWriter(sw)
Dim dg As New DataGrid()
dg.DataSource = ds
dg.DataBind()
dg.RenderControl(htw)
response.Charset = "UTF-8"
response.ContentEncoding = System.Text.Encoding.UTF8
response.BinaryWrite(System.Text.Encoding.UTF8.GetPreamble())
response.Output.Write(sw.ToString())
response.[End]()
End Using
End Using
End Sub
Finally I've solved this issue, after a long time researching. Make the fields inside the details section fill the whole height of the section... no spaces between fields and top and bottom edges.
instead of this
I can't figure out how to write text into a table cell within a document. I can read the cell, getRow(0).getCell(0), but I can't change the text within the cell.
As noted in the comments below, my variable text does show the old cell string has been cleared and the new string inserted; however, the actual cell in my document remains unchanged, containing the original, old string.
var doc = DocumentApp.getActiveDocument().getBody();
var tables = doc.getTables();
var cell = tables[0].getRow(0).getCell(0);
var text = cell.getText(); // the string is the expected from document.
cell.clear();
cell.setText('text');
var text = cell.getText(); // text = 'text' but the cell on document remains unchanged.
Use the .editAsText() to get the Text object inside of the cell.
var text = cell.editAsText();
A strong from the Text object can be retrieved with:
var string = text.getText();
And set with:
text.setText('blahblah');
I am trying to change the font color for specific words with-in a cell. I don't want to change all of the text to the color just specific words. I am using an OfficeWriter ExcelTemplate.
You could use ExcelApplication to Post Process your OfficeWriter Template file.
You want to get a handle on what is referred to as a CharacterRun See the OfficeWriter documentation.
Your code would look something like:
ExcelTemplate xlt = new ExcelTemplate()
//Process Template
ExcelApplication xla = new ExcelApplication();
Workbook wb = xla.Open(xlt)
Worksheet ws = wb.Worksheets[0];
Cell cellA1 = ws.Cells["A1"];
cellA1.Value = "Test";
CharacterRun charRun = cellA1.GetCharacters(0,5);
charRun.Font.Color = Color.Red
In the formula bar, select the words you want to change the color of, then change the text color.