Setting Comments in Excel (with apache poi) - apache

I'm trying to set cell comments to a set of cells, and for the ones that are on the right of the page, the comments have the proper size, but for the others that are on a previous column of the page, their size begin to descrease with no appearent explanation (for me).
Screenshots of the situation:
Comment with the correct size
http://prntscr.com/7ez65x
Starting to became narrower
http://prntscr.com/7ez6bm
And for the ones that are on previous columns, the comments don't have width at all... like they have collapsed on themselves.
The code that i'm using to generate the comments is:
protected void setCellComment(Cell cell, String message)
{
Drawing drawing = cell.getSheet().createDrawingPatriarch();
CreationHelper factory = cell.getSheet().getWorkbook().getCreationHelper();
ClientAnchor anchor = factory.createClientAnchor();
int width = 3;
int height = 2;
anchor.setCol1(cell.getColumnIndex());
anchor.setCol2(cell.getColumnIndex() + width);
anchor.setRow1(cell.getRowIndex());
anchor.setRow2(cell.getRowIndex() + height);
anchor.setDx1(100);
anchor.setDx2(100);
anchor.setDy1(100);
anchor.setDy2(100);
Comment comment = drawing.createCellComment(anchor);
RichTextString str = factory.createRichTextString(message);
comment.setString(str);
cell.setCellComment(comment);
}
Please Help!
Thanks a lot

I solved the problem removing the freezing panes that the sheet had. Probably there is a bug with the combination between freezing panes and comments.

Related

Issues Flexslider mobile view when slides are different heights

First of all I've searched for the solution but couldn't find any..
I'm new at this so I lack experience to solve this, hopefully somebody can help me :)
The Problem:
I use flexslider on my woocommerce product pages. I am having problems only when a product page is opened in mobile browser and when the slides different heights. The first slide is aprox. half the height of the rest of the slides. When opening the product page the last slide lays underneath the first slide and covers the text partially I have beneath it. (so the first picture and the bottom of the last slide are showing). When the animation loop is complete and the slider starts over again the problem is gone? This only happens on mobile views, desktop has no problems.
I have this in functions.php:
add_filter( 'woocommerce_single_product_carousel_options', 'sf_update_woo_flexslider_options' );
function sf_update_woo_flexslider_options( $options ) {
$options['animation'] = 'fade';
$options['slideshow'] = true;
$options['smoothHeight'] = true;
$options['fadeFirstSlide'] = true;
$options['slideshowSpeed'] = 8000;
$options['animationSpeed'] = 3500;
$options['animationLoop'] = true;
$options['randomize'] = false;
$options['pauseOnAction'] = true;
$options['pauseOnHover'] = true;
$options['startAt'] = 0;
$options['easing'] = "swing";
return $options;
}
I have tried several things allready like disabling smoothheight. But I cant figure out whats wrong.
I would really appreciate some help here ;)
(I'm not an experienced coder, not at all..)
One of the pages where this occurs: https://www.littleleloo.com/shop/large-contemporary-abstract-painting-angels-vs-demons/
Thanks and have a lovely day!
Best wishes,
Jessica

QComboBox elided text on selected item

So, I have a QComboBox.
If the currentText() is too long for the widget then I want to show an ellipsis.
Like this :
So :
void MyComboBox::paintEvent(QPaintEvent * )
{
QStylePainter painter(this);
QStyleOptionComboBox opt;
initStyleOption(&opt);
painter.drawComplexControl(QStyle::CC_ComboBox, opt);
QRect rect = this->rect();
//this is not ideal
rect.setLeft(rect.left() + 7);
rect.setRight(rect.width() - 15);
//
QTextOption option;
option.setAlignment(Qt::AlignVCenter);
QFontMetrics fontMetric(painter.font());
const QString elidedText = QAbstractItemDelegate::elidedText(fontMetric, rect.width(), Qt::ElideRight, this->currentText());
painter.drawText( rect, elidedText, option);
}
This is working flawlessy.
The problem is the code in between the comments, because I am hardcoding the distances from the left and right border. It makes me cringe.
The result without that code is:
Does anybody know a more general way to do this, without hardcoding?
Thank you
Where the text should be drawn exactly depends on the used style. You can get information about (some of) the positioning of subelements with QStyle::subControlRect. The subcontrol that matches the combo box text best seems to be QStyle::SC_ComboBoxEditField, though if the item has an icon, this needs to be taken into account as well. If the items do not have icons, you can go with
QRect textRect = style()->subControlRect(QStyle::CC_ComboBox, &opt, QStyle::SC_ComboBoxEditField, this);
QFontMetrics fontMetric(painter.font());
const QString elidedText = QAbstractItemDelegate::elidedText(fontMetric, textRect.width(), Qt::ElideRight, this->currentText());
opt.currentText = elidedText;
painter.drawControl(QStyle::CE_ComboBoxLabel, opt);
You might want to have a look at how e.g. QFusionStyle::drawControl works for details.
In general, if you want all your combo boxes to elide the text, you should consider implementing your own QProxyStyle and only override MyStyle::drawControl for QStyle::CE_ComboBoxLabel.
This is the solution I've been using:
void CustomComboBox::paintEvent(QPaintEvent * /*event*/)
{
QStyleOptionComboBox opt;
initStyleOption(&opt);
QStylePainter p(this);
p.drawComplexControl(QStyle::CC_ComboBox, opt);
QRect textRect = style()->subControlRect(QStyle::CC_ComboBox, &opt, QStyle::SC_ComboBoxEditField, this);
opt.currentText = p.fontMetrics().elidedText(opt.currentText, Qt::ElideRight, textRect.width());
p.drawControl(QStyle::CE_ComboBoxLabel, opt);
}
This approach is very similar to a combination of your sample code and the snippet E4z9 suggested. I just thought I'd include the whole method for others coming here in the future.

RichTextBlock overflow, keep paragraphs together on one page (in one overflow control)

I am printing RichTextBlock contents, using RichTextOverflow for pagination, it's working great but I would like to keep paragraphs together on one page, and now sometimes I have page breaks in middle of paragraph.
Here is the example :
Paragraph 3 should be on the next page, it seems that ITextParagraphFormat.KeepTogether is just what I need but don't know how to get that for RichTextBlock.
If you put your paragraph inside TextBlock/RTB inside InlineUIContainer it will be treated as a single element and will carry over to the next page unbroken if needed. This approach may have some side effects, but I believe it should work for printing.
After all I made a method that will "push" paragraphs that are broken on two pages on to a next page, I am not very happy about this solution but I didn't found another way
public static void BreakBeforeLastParagraph(RichTextBlockOverflow rto)
{
if (!rto.HasOverflowContent)
return;
var pageBreak = rto.ContentEnd.Offset;
var brokenPar = rto.ContentSource.Blocks.FirstOrDefault(pr => pr.ElementStart.Offset <= pageBreak && pr.ElementEnd.Offset >= pageBreak);
if (brokenPar != null)
{
double spacerSize = pageBreak - brokenPar.ElementStart.Offset;
var spacer = new Paragraph();
spacer.Margin = new Windows.UI.Xaml.Thickness(0,spacerSize, 0,0);
rto.ContentSource.Blocks.Insert(rto.ContentSource.Blocks.IndexOf(brokenPar), spacer);
}
rto.UpdateLayout();
}

iTextSharp Table Cell Spacing Possible?

Is it possible to have cell spacing within a table (PdfPTable) in iTextSharp? I can't see anywhere that it is possible. I did see one suggestion of using the iTextSharp.text.Table instead but that doesn't seem available on my version of iTextSharp (5.2.1).
If you're looking for true cell spacing like HTML's then no, the PdfPTable doesn't support that natively. However, the PdfPCell supports a property that takes a custom implementation of IPdfPCellEvent which will get called whenever a cell layout happens. Below is a simple implementation of one, you'll probably want to tweak it to your needs.
public class CellSpacingEvent : IPdfPCellEvent {
private int cellSpacing;
public CellSpacingEvent(int cellSpacing) {
this.cellSpacing = cellSpacing;
}
void IPdfPCellEvent.CellLayout(PdfPCell cell, Rectangle position, PdfContentByte[] canvases) {
//Grab the line canvas for drawing lines on
PdfContentByte cb = canvases[PdfPTable.LINECANVAS];
//Create a new rectangle using our previously supplied spacing
cb.Rectangle(
position.Left + this.cellSpacing,
position.Bottom + this.cellSpacing,
(position.Right - this.cellSpacing) - (position.Left + this.cellSpacing),
(position.Top - this.cellSpacing) - (position.Bottom + this.cellSpacing)
);
//Set a color
cb.SetColorStroke(BaseColor.RED);
//Draw the rectangle
cb.Stroke();
}
}
To use it:
//Create a two column table
PdfPTable table = new PdfPTable(2);
//Don't let the system draw the border, we'll do that
table.DefaultCell.Border = 0;
//Bind our custom event to the default cell
table.DefaultCell.CellEvent = new CellSpacingEvent(2);
//We're not changing actual layout so we're going to cheat and padd the cells a little
table.DefaultCell.Padding = 4;
//Add some cells
table.AddCell("Test");
table.AddCell("Test");
table.AddCell("Test");
table.AddCell("Test");
doc.Add(table);
The Table class has been removed from iText starting from 5.x, in favor of PdfPTable.
As for spacing, what you are looking for are the setPadding methods.
Have a look at iText's API for more information:
http://api.itextpdf.com/itext/com/itextpdf/text/pdf/PdfPCell.html
(It's for the Java version, but the C# port maintains the names of the methods)

SWT Composite maximum size

I have a ScrolledComposite, the contents of which are being truncated. I have Googled and am aware that it is a known issue on Windows.
The only suggested workaround I can find is to use the canvas.scroll functionality.
Given the age of the issue, I was wondering if there is a nicer workaround?
Thank you!
(EDIT: At the time of writing, the link was: http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet48.java?view=markup&content-type=text%2Fvnd.viewcvs-markup&revision=HEAD)
(the link you posted gave a 400 Error)
Not sure if my issue was the same, but I ran into a truncation issue with ScrolledComposite as well. The problem was that when I resized the Composite to be scrolled and the Scrollbar became visible, the controls didn't account for the space taken up by the scrollbar. To solve this, I added a kind-of recursive bit of code to my Resize listener on the scrolled composite:
After you have set the size of your content composite, check if the scrolledComposite's scrollbar (getVerticalBar() for example) has just become visible. If so, send a new Resize event to your listener. Here's a snippet from my code...
public void handleEvent(Event event)
{
int newWidth = scrolledComposite.getSize().x;
boolean hasScroll = false;
ScrollBar scrollBar = scrolledComposite.getVerticalBar();
if (scrollBar.isVisible())
{
hasScroll = true;
newWidth -= scrolledComposite.getVerticalBar().getSize().x;
}
newWidth -= 8;
Point size = contentComposite.computeSize(newWidth, SWT.DEFAULT);
contentComposite.setSize(size);
int scroll_multiplier = size.y / 50;
scrollBar.setIncrement(scroll_multiplier);
/**
* If the scroll bar became visible because of the resize, then
* we actually need to resize it again, because of the scroll
* bar taking up some extra space.
*/
if (scrollBar.isVisible() && !hasScroll)
{
scrolledComposite.notifyListeners(SWT.Resize, null);
}
}
Hope this helps!
Edit: wow I didn't notice the date of the OP. Hope this ends up helping someone either way...