Unable to find Open XML word Table top border element - c#

I am creating a table in MS Word the table looks like as shown below .
I then ZIP the file and open the document.xml and check for the border elements in the table grid . this is how it looks . I am checking the for border element that is the top border element.
All the border are displayed as none . Then i check the TableGrid in the styles.xml file for table borders below is how the TableGrid styles look like in the styles.xml
The problem here is i am not able to find where exactly is the border element getting assigned. The top black line in the table ?

Borders can be defined at table level via TableStyle (here w:tblBorders in TableGrid style) or via tablesProperties (here w:tblBorders in w:tblPr).
If both of them are definied, there is a conflict and borders definied via tablesProperties will win.
Since the w:tblBorders in w:tblPr are set to None, there is no borders.
But I noticed that TopBorder is missing here (you have Left, Right, Bottom InsideH and InsideV),
It's why, for the TopBorder, MS Word is using the TopBorder definied in TableGrid style and it is set to Single.
So, to remove the top border, you have to :
add the TopBorder which is missing in w:tblBorders in w:tblPr (and set it to none like others)
Or set the borders to None in the TableGrid style.

Related

PDFsharp MigraDoc set height of element

Is there a way to set fixed height of an element? Could be a table, row or section. This element is dynamically generated from database and it can have a variable number of rows. I need to do that, because the section below needs to be in a fixed position for print out. I am using WPF v1.31. I know it is not the latest, but it's an addition to a quite old application.
You can set the height of a Paragraph or a table Row.
I think you cannot set the height of a Table - but that will be the sum of the heights of all rows. Automatic page breaks will make things complicated if a table does not fit a single page.
A Section always starts on a new page.
TextFrame can be used to place text at a fixed position. Depending on the requirements, this could be simple or complicated.
You can prepare a document to let MigraDoc determine sizes and positions. Then you code can decide whether the items with the fixed position will be on the same page or on a new page.
Here is sample code that shows how to show the progress while creating a PDF:
http://forum.pdfsharp.net/viewtopic.php?f=8&t=3172
The same technique can be used to stitch several MigraDoc documents together to create a single PDF. If I understand your requirements correctly, this could be the way to go - without setting the height of any elements.

How to set document level properties in MigraDoc?

I wanted to find a way to set the document level properties in MigraDoc. For example I want to set all margins (top, left, right, bottom) to 5 or want to set the font for whole PDF document once. I don't want to set them in each section or paragraph. I know I can set them in sections but my document will have three different sections (header, contents and footer) therefore it is very annoying to repeat the same code for setting same properties in each section.
Moreover, I have set top margin to 5 for header section however top margin seems to be more than 5 (looks like at least 10). Thanks for help.
Margins set for the first section are inherited by the following sections. If you need the same margins for all sections, only set them for the first section.
Use a Style to set the font. Many styles are set by default (like in word), but you can add more styles as needed.
All styles are derived from the Normal style. Set the font for Normal only to change the font for the complete document.
To use a different style, specify its stylename at the paragraph.
See also:
http://pdfsharp.net/wiki/HelloMigraDoc-sample.ashx
(and the other samples)
Re Top Margin: some fonts reserve space for an ascender (accents, diacritical marks, ...) that may make the top margin look bigger than it is.

Align label in UITableViewCell on the right with Auto Layout

I want to use auto layout for may table view cell content. This worked so far. Now I want to align a UILabel on the right side of the table view. If I do this, it isn't aligned right. Instead it is completely on the left side. So it seems the width of the table view is not calculated when the constraint is applied. I tried two different approaches:
No. 1:
this.ContentView.AddConstraints (NSLayoutConstraint.FromVisualFormat ("H:[iNumberLabel]-|", (NSLayoutFormatOptions)0, null, viewsDictionary));
No. 2:
this.ContentView.AddConstraint (NSLayoutConstraint.Create (iNumberLabel, NSLayoutAttribute.Right, NSLayoutRelation.Equal, this.ContentView, NSLayoutAttribute.Right, 1, 0));
The constraints are added in UpdateConstraints in my table view cell subclass. The code is in C# but that doesn't matter. I would be glad if you could provide a solution.
This format string: "H:|-[iNumberLabel]-|"
tells the system to pin the label to both sides of the cell with the default padding, so the label will be nearly the width of the cell. You should get rid of the spacing to the left side, if you want it right aligned,
"H:[iNumberLabel]-|"
I don't know why the second method didn't work. If that's the only horizontal constraint that you had, it should have worked.
In addition to pinning it to the right side with:
"H:[iNumberLabel]-|"
You should also rightAlight the text with:
cell.textLabel.textAlignment = NSTextAlignmentRight;
Edit: Only working for iOS 8. Currently no solution for iOS 7.
This was the culprit
this.ContentView.TranslatesAutoresizingMaskIntoConstraints = false;
I had this set when I created and added my labels as subview. When this is turned off the width of the cell seems to not get correctly laid out. Perhaps one has to add some additional constraints for the ContentView, but I don't know which (content view to super view?).
Auto resizing mask has to be enabled for the content view.

Draw a borderless table in iTextSharp

It appears as though the PDfPCell class does have a border property on it but not the PdfPTable class.
Is there some property on the PdfPTable class to set the borders of all its contained cells in one statement?
Borders are defined at the level of the cell, not at the level of the table. Hence: if you want to remove the borders of the table, you need to remove the borders of each cell.
By default, each cell has a border. You can change this default behavior by changing the border of each cell. For instance: if you create PdfPCell objects, you use:
cell.setBorder(Rectangle.NO_BORDER);
In case the cells are created internally, you need to change that property at the level of the default cell. See What is the PdfPTable.DefaultCell property used for?
table.getDefaultCell().setBorder(Rectangle.NO_BORDER);
For special borders, for instance borders with rounded corners or a single border for the whole table, or double borders, you can use either cell events or table events, or a combination of both. In Chapter 5 of my book "iText in Action - Second Edition", you'll find a PDF with double borders. See the PressPreviews example to see how this was done. Note that all examples from the book were ported to C#. You can find these examples here.
The official site also has examples where the borders are dotted lines, have rounded corners, and so on.
iTextSharp has no setBorder() method.
I tried the following:
cell.HasBorder(Rectangle.NO_BORDER); // <= this did nothing
cell.BorderColor = BaseColor.WHITE; // <= this works for me, but if your document's background is not white, you might not like it
cell.BorderWidth = 0; // <= this works like gangbusters
So it seems the "safest" way to go is to set BorderWidth to zilch AKA nada.
The following worked for me.
cell.Border = Rectangle.NO_BORDER;

How to control winform mschart legend text alignment c#?

How does one set the alignment of text within a chart legend object? I've tried using:
myChartName.Legends["mySeriesName"].Alignment = stringAlignment.Near
With no effect. I've also tried to create custom legend items, again resulting in no effect. Text is ALWAYS centered (along with the series marker) in the legend "box". The only text I have been able to align is the title, but I don't need titles in my application.
My research to date says the legend object is basically a table with (by default) two cells. If that is the case there should be a way to access those cells and manipulate them as table cells. So, what gives? Why can't I access the text alignment properties of the legend object? Clearly, there is something I'm missing, but for the life of me I can't seem to figure this out. Quite frustrating.
Problem solved. The CustomItem approach wasn't working either, so I tried using the LegendCellColumn Class.
I changed the LegendStyle from Column to Row, then added two CellColumns, one for the series symbol and one for the legend text. Set the alignment, margins, and column widths (that turned out to be the trick), and voila; a legend that looks like I want. Here's the code for anyone with a similar issue.
chartSel.Legends[ySeries.Name].CellColumns.Add(new LegendCellColumn("", LegendCellColumnType.SeriesSymbol, ""));
chartSel.Legends[ySeries.Name].CellColumns[0].Alignment = ContentAlignment.TopLeft;
chartSel.Legends[ySeries.Name].CellColumns[0].Margins = new System.Windows.Forms.DataVisualization.Charting.Margins(0, 0, 1, 1);
chartSel.Legends[ySeries.Name].CellColumns[0].MinimumWidth = 250;
chartSel.Legends[ySeries.Name].CellColumns[0].MaximumWidth = 250;
chartSel.Legends[ySeries.Name].CellColumns.Add(new LegendCellColumn("", LegendCellColumnType.Text, ySeries.Name));
chartSel.Legends[ySeries.Name].CellColumns[1].Alignment = ContentAlignment.MiddleLeft;
chartSel.Legends[ySeries.Name].CellColumns[1].Margins = new System.Windows.Forms.DataVisualization.Charting.Margins(0, 0, 1, 1);
chartSel.Legends[ySeries.Name].CellColumns[1].MinimumWidth = 1500;
chartSel.Legends[ySeries.Name].CellColumns[1].MaximumWidth = 1500;
It's probably not the most efficient way to do it, but it works. Technically, the legend symbol and text are still centered in the object, but because I'm forcing the widths of the two columns it has the appearance of being left-justified.
Hopefully, this may help another newbie like me avoid days of consternation.
My understanding is that Legend alignment relates to the Docking property, not really how the text is aligned within the legend. So setting Alignment to Near means positioning the legend box near the Docking direction.
It is quite hard to explain this textually. The MS Chart Samples have a subsection named Chart features -> Legends -> Style and Auto Positioning which will help you play with those two properties and understand how they are meant to work.
For inner legend alignment, you may need to use Legend.CustomItems and define LegendCell individually.
chart.Legends["Default"].CustomItems.Clear();
chart.Legends["Default"].CustomItems.Add(new LegendItem("LegendItem", Color.Red, ""));
chart.Legends["Default"].CustomItems[0].Cells.Add(new LegendCell(LegendCellType.Text, "My text", ContentAlignment.MiddleLeft));
This is described inside the Chart features -> Legends -> Legend Cells section of the samples.
While continuing to try to figure this out I stumbled on this tidbit of info from the following MSDN library page:
http://msdn.microsoft.com/en-us/library/dd456711(v=vs.100).aspx
"NOTE: You cannot adjust the individual legend items and cells in the Chart.Legends collection. To adjust them, use custom legend items."
So, back to the CustomItem route. I've got this code gleaned from several sources (including you, Dominique, thanks):
chartSel.Legends.Add(ySeries.Name);
chartSel.Series[ySeries.Name].IsVisibleInLegend = false;
chartSel.Legends[ySeries.Name].CustomItems.Clear();
LegendItem li = new LegendItem();
li.ImageStyle = LegendImageStyle.Line;
li.Cells.Add(LegendCellType.SeriesSymbol, "", ContentAlignment.TopLeft);
li.Cells[0].BackColor = Color.CornflowerBlue; //color is only to see the cell bounds
li.Cells.Add(LegendCellType.Text, ySeries.Name, ContentAlignment.TopLeft);
li.Cells[1].BackColor = Color.Aquamarine; //color is only to see the cell bounds
chartSel.Legends[ySeries.Name].CustomItems.Add(li);
From what I can find it should work, but it doesn't. It results in a legend object with two cells; the first is empty and the second has left-justified text. I tried to post an image of it, but the system says I'm not yet worthy.
Why there is no line for the series symbol is also a mystery, but that's another problem to solve. The text justification issue is my main concern at the moment. It looks like the text within the cells is left-justified as desired, but the cells themselves are centered in the legend object; not what I wanted. I want those cells to be left-justified in the object too, so the first cell is against the left edge of the legend object.
Ideas?

Categories