I have a Table made of many PdfPcell like this:
enter code cell = New PdfPCell(New Phrase(txt0, myfontB))
cell.BackgroundColor = New BaseColor(System.Drawing.ColorTranslator.FromHtml("#f5f5f5"))
cell.PaddingTop = 15
cell.PaddingBottom = 15
cell.Border = 0
cell.Colspan = 2
tablegg.AddCell(cell)
cell = New PdfPCell(New Phrase(txt1, myfontN))
cell.BackgroundColor = New BaseColor(System.Drawing.ColorTranslator.FromHtml("#f5f5f5"))
cell.PaddingTop = 15
cell.PaddingBottom = 5
cell.Border = 0
cell.Colspan = 2
tablegg.AddCell(cell) here
My problem it's, where txt1 is long the PdfPcell is wrote directly next page, instead to continue part on first page and the rest on next page.
Any suggestion how to fix it?
Tks
V
Related
I am writing a macro to generate pie chart in OpenOffice Basic but I can't find the method to change the colour of the different part of the pie.
We can take as example the macro of this subject:
OpenOffice Calc macro to add pie chart
That is, my data are:
And my code:
Sub Macro1
Dim oRange as Object
Dim oRangeAddress(1) As New com.sun.star.table.CellRangeAddress
Dim oRect As New com.sun.star.awt.Rectangle
Dim cTitle as String
oRange = thisComponent.getCurrentSelection.getRangeAddress
oSheets = ThisComponent.getSheets()
oSheet = oSheets.getByIndex(0)
oCharts = oSheet.Charts
oRect.Width = 10000
oRect.Height = 10000
oRect.X = 8000
oRect.Y = 1000
oRangeAddress(0).Sheet = oRange.Sheet
oRangeAddress(0).StartColumn = 0
oRangeAddress(0).StartRow = 0
oRangeAddress(0).EndColumn = 1
oRangeAddress(0).EndRow = 2
cTitle = "Test Results"
oCharts.addNewByName(cTitle,oRect,oRangeAddress(),TRUE, TRUE)
oChart = oCharts.getByName(cTitle).embeddedObject
oChart.Diagram = oChart.createInstance("com.sun.star.chart.PieDiagram")
oChart.HasMainTitle = True
oChart.Title.String = cTitle
End Sub
How can I get some green in my chart, instead of blue, for example?
Thank you for your help.
Here is one solution.
Sub Macro1
...
oFirstDiagram = oChart.getFirstDiagram()
oColorScheme = CreateUnoListener("XColorScheme_", "com.sun.star.chart2.XColorScheme")
oFirstDiagram.setDefaultColorScheme(oColorScheme)
End Sub
Function XColorScheme_getColorByIndex(index As Integer) As Long
Dim result As Long
result = &H0000FF ' blue
If index = 0 Then
result = &H00FF00 ' green
ElseIf index = 1 Then
result = &HFFFF00 ' yellow
End If
XColorScheme_getColorByIndex = result
End Function
The only relevant documentation I could find for this approach is the API docs: https://www.openoffice.org/api/docs/common/ref/com/sun/star/chart2/XDiagram.html.
Another way is to put the colors in column C.
Status Count Color
Unfinished 20 =COLOR(0,255,0)
Finished 30 =COLOR(255,0,0)
Then set the Range for Fill Color to use column C. If you want to see code for this second approach, post a comment and I'll look into it.
Yet another way is from https://forum.openoffice.org/en/forum/viewtopic.php?t=36001.
oChart.Diagram.DataRowSource = com.sun.star.chart.ChartDataRowSource.COLUMNS
oChart.FirstDiagram.CoordinateSystems(0).ChartTypes(0).DataSeries(0).Color = &H00FF00
However, this last approach did not change the color when I tried it.
I have a nested cell of cells like the one below:
CellArray={1,1,1,{1,1,1,{1,1,{1,{1 1 1 1 1 1 1 1}, 1,1},1,1},1,1,1},1,1,1,{1,1,1,1}};
I need to randomly pick a location in CellArray. All members' locations of CellArray must have same chances to be chosen in the random selection process. Thanks.
You can capture the output of the celldisp function. Then use regex to extrcat indices:
s=evalc('celldisp(CellArray,'''')');
m = regexp(s, '\{[^\=]*\}', 'match');
Thanks to #excaza that suggested a clearer use of regexp
Result:
m =
{
[1,1] = {1}
[1,2] = {2}
[1,3] = {3}
[1,4] = {4}{1}
[1,5] = {4}{2}
[1,6] = {4}{3}
[1,7] = {4}{4}{1}
[1,8] = {4}{4}{2}
[1,9] = {4}{4}{3}{1}
[1,10] = {4}{4}{3}{2}{1}
[1,11] = {4}{4}{3}{2}{2}
[1,12] = {4}{4}{3}{2}{3}
[1,13] = {4}{4}{3}{2}{4}
[1,14] = {4}{4}{3}{2}{5}
[1,15] = {4}{4}{3}{2}{6}
[1,16] = {4}{4}{3}{2}{7}
[1,17] = {4}{4}{3}{2}{8}
[1,18] = {4}{4}{3}{3}
[1,19] = {4}{4}{3}{4}
[1,20] = {4}{4}{4}
[1,21] = {4}{4}{5}
[1,22] = {4}{5}
[1,23] = {4}{6}
[1,24] = {4}{7}
[1,25] = {5}
[1,26] = {6}
[1,27] = {7}
[1,28] = {8}{1}
[1,29] = {8}{2}
[1,30] = {8}{3}
[1,31] = {8}{4}
}
Use randi to select an index:
m{randi(numel(m))}
I need the below macro to reference another sub change event to loop reference to the row number of the scroll bar, i and then adjust the cell Bi . So far I can only get 100 scroll bars to reference only B2
Sub Tester88()
Dim ScrollBar As Object
Dim rng As Range
Dim i As Long
Dim lastRow As Long
lastRow = 99 'Modify as needed this will be the last possible row to add a button
For i = 2 To lastRow Step 4
Set rng = ActiveSheet.Cells(i, 18) 'Column 3, row i
'## Create the button object and assign a variable to represent it
Set ScrollBar = ActiveSheet.ScrollBars.Add(1, 1, 1, 1)
'## use the btn variable to manipulate the button:
With ScrollBar
.Top = rng.Top
.Left = rng.Left
.width = rng.width
.height = rng.RowHeight
.Value = 1
.Min = 1
.Max = 100
.SmallChange = 1
.LargeChange = 10
.LinkedCell = "$B$2"
.Display3DShading = True
End With
Next
End Sub
It looks like you can just put the row in .LinkedCell instead of having it hardcoded. You've set it to a range of 1-100; keep in mind if you are using LinkedCell you are directly controlling the value of the cell, so if you are controlling data that has an existing set of values you need to either set the range (and the value) to the existing value of the cell, or have it as a cell that just shows the scroll bar value and use a formula referencing that cell for the final result you want.+
I've solved this task, so:
Sub Tester88()
Dim ScrollBar As Object
Dim rng As Range
Dim i As Long
Dim lastRow As Long
lastRow = 99 'Modify as needed this will be the last possible row to add a button
For i = 2 To lastRow Step 4
Set rng = ActiveSheet.Cells(i, 13) 'Column 3, row i
'## Create the button object and assign a variable to represent it
Set ScrollBar = ActiveSheet.ScrollBars.Add(1, 1, 1, 1)
'## use the btn variable to manipulate the button:
With ScrollBar
.Top = rng.Top
.Left = rng.Left
.Width = rng.Width
.Height = rng.RowHeight
.Min = 1
.Max = 100
.SmallChange = 1
.LargeChange = 1
.LinkedCell = "B" & i
End With
Next
End Sub
I am using iText5 (Java) to write a PDF which may contain Chinese characters. So I am using FontSelector to process the String and this works fine.
Now the problem is that if there are 2 strings
String str1 = "Hello Test1";
String str2 = "Hello Test2";
I need to write str1 witch Font Color = Blue and size = 10, whereas str2 with Font Color = Gray and size = 25.
I am not able to figure out how to achieve this using FontSelector.
Any help is appreciated.
That's easy. Here you have a code snippet that adds the Times Roman text in Blue and the Chinese text in Red:
FontSelector selector = new FontSelector();
Font f1 = FontFactory.getFont(FontFactory.TIMES_ROMAN, 12);
f1.setColor(BaseColor.BLUE);
Font f2 = FontFactory.getFont("MSung-Light",
"UniCNS-UCS2-H", BaseFont.NOT_EMBEDDED);
f2.setColor(BaseColor.RED);
selector.addFont(f1);
selector.addFont(f2);
Phrase ph = selector.process(TEXT);
In your case you need two FontSelectors.
FontSelector selector1 = new FontSelector();
Font f1 = FontFactory.getFont(FontFactory.TIMES_ROMAN, 12);
f1.setColor(BaseColor.BLUE);
selector1.addFont(f1);
Phrase ph = selector1.process(str1);//First one
FontSelector selector2 = new FontSelector();
Font f2 = FontFactory.getFont(FontFactory.TIMES_ROMAN, 12);
f2.setColor(BaseColor.GRAY);
selector2.addFont(f2);
Phrase ph = selector2.process(str2);//Second one
you can do it in another way in my case i use 14 for header and 10 for data in tabular report
private Font fHeader;
private Font f1;
BaseFont bf = BaseFont.createFont(Constants.Settings.ARIAL_FONT, BaseFont.IDENTITY_H, true);
f1 = new Font(bf, 10);
fHeader= new Font(bf,14);
PdfPCell cell = new PdfPCell();
//for report header
cell = new PdfPCell(new Phrase(reportKingdomData + "\n" + departmentData + " " + username + " \n " + reportHeader + " \n ", fHeader));
//and for background color
cell .setBackgroundColor(new GrayColor(0.40f));//if 0.10f will be closer to black
i am working on a project which is migrated from vb6 to vb.net.And during working with the crystal reports i got this problem.Actually i have to print the axmschart of my application in reports.So i am using the following code :
gtmpString = Application.StartupPath & gsGraphPicPath
Dim myPic As New Bitmap(_chtAnlysGraph_0.AsBitmap)'''''ERROR here...as bitmap is not a member of AXMSCHART''''''''
PictureBox1.Image = myPic
PictureBox1.Image.Save(gtmpString, System.Drawing.Imaging.ImageFormat.Png)
Dim intCount As Short
Dim dRow As DataRow
Dim dTable As New DataTable
Dim dt As New DataSetResults.AnalysisTableDataTable 'Report filling
dTable = dt.Copy
dRow = dTable.NewRow
For intCount = 1 To msgAnlysData.Rows - 1
dRow = dTable.NewRow
dRow.Item("Sr_No") = msgAnlysData.get_TextMatrix(intCount, 1)
dRow.Item("abs_val") = msgAnlysData.get_TextMatrix(intCount, 2)
dRow.Item("pt_conc") = msgAnlysData.get_TextMatrix(intCount, 3)
dRow.Item("lin_conc") = msgAnlysData.get_TextMatrix(intCount, 4)
dRow.Item("poly_conc") = msgAnlysData.get_TextMatrix(intCount, 5)
'If gtmpString = True Then
gtmpString = Application.StartupPath & gsGraphPicPath
dRow.Item("graph1") = savepic(gtmpString)
' End If
If msgAnlysData.get_TextMatrix(intCount, 2) = Nothing Then
Else
dTable.Rows.Add(dRow)
End If
Next intCount
Help me out here plzz.
Dim myPic As New Bitmap(_chtAnlysGraph_0)