MvvmCross TitleText - xamarin.ios

The title of rows in table cells is set as follows.
var source = new MvxStandardTableViewSource(TableView, "TitleText FullName");
How is a subtitle text set along with the TitleText?

If you are using a standard cell type which has a subtitle, then you can use DetailText - see the property in MvxStandardTableViewCell.cs#L73
e.g.
var source = new MvxStandardTableViewSource(
TableView,
UITableViewCellStyle.Subtitle,
"MyCellId",
"TitleText FullName; DetailText Address");
Obviously the standard cell types are fairly limited in what they can display - for more advanced applications, it's best to switch to custom cell types. There are several articles and videos about how to do this - see http://mvvmcross.wordpress.com

Related

Increasing height merged cells Apache POI

I am using Apache POI SXSSF to generate xlsx document. The document uses Times New Roman sizes 9 and 11, and the default cell width and height have been changed. The question is how to calculate the height of the merged cells so that all the text fits (the height of the cell must be dynamically set according to the given text)? The server running the application does not have a display, and this code is running in the IBM Integration Bus.
The solution from How to get the needed height of a multi line rich-text field (any font, any font size) having defined width using Java? is not suitable. The server running the application is missing a display and the string int ppi = java.awt.Toolkit.getDefaultToolkit().getScreenResolution(); returns an exception, and manually picking the ppi value is also not possible. If there is a display, everything works correctly.
And is there any way to use the "align center selection" function somehow?
I found that centering a selection gives a similar result as merging multiple cells horizontally, but I couldn't find an answer anywhere on how to use this in Apache POI. As a result, experimentally, I found out that in order to achieve this effect, you need to do the following things:
Create CellStyle; specify setWrapText(true) and setAlignment(HorizontalAlignment.CENTER_SELECTION) for it
Apply the style created in step 1 to all cells that need to be merged
Specify the value in the first cell
Code example:
Font font = wb.createFont(); // where wb - is SXSSFWorkbook object
font.setFontName("Times New Roman");
font.setFontHeightInPoints((short) 11);
CellStyle style = wb.createCellStyle();
style.setFont(font);
style.setWrapText(true);
style.setAlignment(HorizontalAlignment.CENTER_SELECTION);
for (int i = 0; i <= endCellNum - firstCellNum; i++){ // where endCellNum - number of last cell of selection and firstCellNum is number of first cell of selection
Cell cell = curRow.createCell(firstCellNum + i);
cell.setCellStyle(cs);
if (i == 0){
firstCell = cell;
}
}
firstCell.setCellValue(value);

Apache POI - watermark in Excel - different appearence in Excel and LibreOffice

I follow the sample and add pictures as watermark like the following:
private void addWaterMark4AllSheets() {
final BufferedImage image = FontImage.createWatermarkImage();
// Export to byte stream B
final ByteArrayOutputStream os = new ByteArrayOutputStream();
try {
ImageIO.write(image, "png", os);
} catch (final IOException e) {
e.printStackTrace();
}
final XSSFWorkbook wb = (XSSFWorkbook) workBook;
final int pictureIdx = wb.addPicture(os.toByteArray(), Workbook.PICTURE_TYPE_PNG);
final POIXMLDocumentPart poixmlDocumentPart = wb.getAllPictures().get(pictureIdx);
// ((XSSFSheet )(schreiben.getSheet()).
for (int i = 0; i < workBook.getNumberOfSheets(); i++) {// Get each Sheet
final XSSFSheet sheet = wb.getSheetAt(i);
final PackagePartName ppn = poixmlDocumentPart.getPackagePart().getPartName();
final String relType = XSSFRelation.IMAGES.getRelation();
// add relation from sheet to the picture data
final PackageRelationship pr = sheet.getPackagePart().addRelationship(ppn, TargetMode.INTERNAL, relType,
null);
// set background picture to sheet
sheet.getCTWorksheet().addNewPicture().setId(pr.getId());
}
}
In general the approach works quite fine. A picture is added into the Excel. But the appearance is different.
In Excel: the image is displayed in the background during the editing (of the sheets). But it is NOT displayed when I print the sheet.
In LibreOffice (7.1): the image is NOT displayed during the editing (of the sheet) - but is printed.
Is there a chance to fix it for working in both Spreadsheets?
There is nothing what apache poi could change as this behavior is by design in the different spreadsheet softwares.
Your linked code example does not creating watermarks. Watermark functionality is not available in Microsoft Excel. Instead it adds background pictures to sheets.
Microsoft itself states: You cannot print a background graphic for a Excel worksheet. So using Microsoft Excel the sheets background graphics only are visible in Excel GUI but not in prints.
In LibreOffice those background graphics are called watermarks but Libreoffice states in Defining Graphics or Colors in the Background of Pages (Watermark):
In spreadsheets this background appears only in the print behind the
cells not formatted elsewhere.
So using Libreoffice the sheets background graphics are visible in prints only.
So what you had observed is by design.
In Add or remove a sheet background Microsoft describes methods to mimic a watermark in Excel. The usage of a picture in a header or footer to mimic a watermark using apache poi is described in apache POI adding watermark in Excel workbook. But this also means a print watermark. So the watermark is visible in print preview and print only. It is not visible in sheet's GUI. And the option to add picture in a header or footer to mimic a watermark is Excel only. LibreOffice does not provide that feature.
Conclusion:
There is not a possibility to have a functionality similar to a watermark which works in Excel and LibreOffice the same way.

How to make a part of string bold in a in a UI label

I want to make bold some part of a big string. I am using Xamarin iOS and getting a big string from API. I need to make some part of the string as bold I tried <b>some text </b> this will not work for mono touch. What is the best option to make a string bold in run time in xamrin. iOS or in winforms applications?
Use AttributedString to apply attributes to different parts of the string. See example below that will only make the first half of the string bold
var BoldString = new NSMutableAttributedString (original_string);
var BoldTextAttributes = new UIStringAttributes {
Font = UIFont.FromName ("Helvetica-Bold", 20f)
};
BoldString.SetAttributes (BoldTextAttributes.Dictionary, new NSRange (0, OutOfStock.Length / 2)); // this range will apply the attribute only to the first half of the string
MyLabel.AttributedText = BoldString; // Assign the attributed text to your label

HowTo: Visio SDK page Re-Layout FlowChart Top to Bottom

I'm creating a dynamic VSD from a hierarchical set of data that represents a flowchart. I don't want/need to fuddle with absolute positioning of these elements - the automatic layout options will work just fine.
The problem is I can't figure out how to perform this command via code. In the UI (Visio 2010), the commands are on the ribbon here: Design (tab) -> Layout (group) -> Re-Layout (SplitButton).
Any of these will do. Looking through the Visio SDK documentation and Googling for a couple days have turned up nothing of very much use.
Any ideas? (using C#, but VB/VBA would do)
The Page.Layout() method itself is not enough.
In the WBSTreeView.sln sample project (VB.Net) I found how to accomplish this, but couldn't post my answer until 8 hours later :-x
The other layout types are possible by looking through the enums used below.
Compact -> DownRight just ended up being better for most of the flows we're creating.
Translated to C#:
// auto-layout, Compact Tree -> Down then Right
var layoutCell = this._page.PageSheet.get_CellsSRC(
(short)VisSectionIndices.visSectionObject,
(short)VisRowIndices.visRowPageLayout,
(short)VisCellIndices.visPLOPlaceStyle);
layoutCell.set_Result(
VisUnitCodes.visPageUnits,
(short)VisCellVals.visPLOPlaceCompactDownRight);
layoutCell = this._page.PageSheet.get_CellsSRC(
(short)VisSectionIndices.visSectionObject,
(short)VisRowIndices.visRowPageLayout,
(short)VisCellIndices.visPLORouteStyle);
layoutCell.set_Result(
VisUnitCodes.visPageUnits,
(short)VisCellVals.visLORouteFlowchartNS);
//// to change page orientation
//layoutCell = this._page.PageSheet.get_CellsSRC(
// (short)VisSectionIndices.visSectionObject,
// (short)VisRowIndices.visRowPrintProperties,
// (short)VisCellIndices.visPrintPropertiesPageOrientation);
//layoutCell.set_Result(
// VisUnitCodes.visPageUnits,
// (short)VisCellVals.visPPOLandscape);
// curved connector lines
layoutCell = this._page.PageSheet.get_CellsSRC(
(short)VisSectionIndices.visSectionObject,
(short)VisRowIndices.visRowPageLayout,
(short)VisCellIndices.visPLOLineRouteExt);
layoutCell.set_Result(
VisUnitCodes.visPageUnits,
(short)VisCellVals.visLORouteExtNURBS);
// perform the layout
this._page.Layout();
// optionally resize the page to fit the space taken by its shapes
this._page.ResizeToFitContents();
//
Changing Connector Line Colors
If you're unfamiliar with how formulas for colors work, this might also be very frustrating. By default you can give an int as a string to get pre-defined colors, but this isn't very helpful because there isn't an easy way to figure out what each of those colors are. (There is a Page.Colors collection, but you have to inspect each of their RGB values and figure out the color from them.)
Instead, you can use your own RGB values for the formula.
private void SetConnectorLineColor(Shape connector, string colorFormula)
{
var cell = connector.get_Cells("LineColor");
cell.Formula = colorFormula;
}
internal static class AnswerColorFormula
{
public static string Green = "RGB(0,200,0)";
public static string Orange = "RGB(255,100,0)";
public static string Yellow = "RGB(255,200,0)";
public static string Red = "RGB(255,5,5)";
}
Call the Layout method on the Page object. If there are shapes selected on this page then this method will only operate on the current selection. You may want to call DeselectAll on the ActiveWindow first.

JExcelApi: multiple formats in one cell?

In Excel, I can have multiple text styles in a single cell. Is there a way to create a file like this using JExcelApi? I'm not seeing anything so far: setCellFormat is a method on WritableCell, and there doesn't seem to be any way to set a format for anything within a single cell.
Am I just missing it (quite possible!), or is this not implemented?
As a bonus: how hard would this be to implement? Is there any other Excel-export library which does implement this, from which I could borrow the code?
#Cosmic There is another way to read that question: multiple formats in separate areas of a single cell.
Like: "Italics Bold Text" with "italics" and "bold" set in different style, i.e. bold not italics, respectively.
Can this be done in JExcelAPI? I am not aware of this. Anyone?
With variables WritableSheet ws, int col, int row
The following code will set your cell's font to bold.
WritableCell wc = ws.getWritableCell(col, row);
WritableCellFormat cf = wc.getCellFormat() != null ? new WritableCellFormat(wc.getCellFormat()) : new WritableCellFormat();
WritableFont wf = new WritableFont(cf.getFont());
try {
wf.setBoldStyle(WritableFont.BOLD);
// refer to http://jexcelapi.sourceforge.net/resources/javadocs/2_6_10/docs/jxl/write/WritableFont.html for other text styles
cf.setFont(wf);
wc.setCellFormat(cf);
} catch ...
A CellFormat/WritableCellFormat contains lots of different formatting options, such as the font, borders, background colour and wrap.
So, yes. You were just missing it :p
EDIT: As I didn't make it clear enough, for multiple styles you can call multiple methods on your WritableFont, e.g setBoldStyle(), setItalic(), setUnderlineStyle(), setStruckout(), setColour(), etc.

Resources