How do I identify merged cells in PowerPoint 2007? Is there anyway we could find a particular cell is merged.
In 2003 we tried to access the Fill.Visible property of a cell and when it throws an error we can identify the cell as a merged cell. How do we achive this in 2007?
It's tough. However, the best way I've found is to check the width of the cell. This code isn't the best as it catches every cell, but it could be a starting point for you:
Dim r As Row
Dim co As Column
Dim c As Cell
For Each co In tbl.Columns
For Each c In co.Cells
If c.Shape.Width <> co.Width Then
Debug.Print "Is merged cell"
End If
Next
Next
In a 2x2 table where cells 2.1 and 2.2 are merged (i.e. the second row is now one cell), this will print "Is merged cell" twice because internally the table still maintains cells 2.1 and 2.2. But it's a starting point as stated...
I think much better would be to compare c1.Left == c2.Left && c1.Top == c2.Top. This would mean that the 2 cells are merged. To traverse all the cells just once I just remove "duplicates" using LINQ's Distinct and custom Comparer.
Cells that are merged together will have the same cell.Shape.Name. Unfortunately while this works on PowerPoint 2003, you get NotImplementedException when asking for the name of these Shapes on PowerPoint 2007. I don't know about later versions.
Recently, I dug into the mystery of merged cells in the PowerPoint table.
I ended up figuring out my own methods to deal with merged cells.
Please refer to the following link:
https://stackoverflow.com/a/74563860/6354194
There are a few useful functions for merged cells:
test if the cell is merged
test if the cell is the first(Top-Left) cell of the merged area
get the index no. of the cells in the merged area, top to bottom, left to right
get the width and height of merged area
test if the given cells are within a merged area
Related
I have already draw an excel chart with EPPlus in C# and I need to set Connect data points with line, in order to avoid empty cells affecting my chart.
As you can see in above image, there are two cells with no value (Green ones) and I checked the "Connect data points with line" in excel data options.
But working with EPPlus, I cant find the proper property to set that.
Unfortunately, your reported problem of EPPLus has not been resolved yet! So, as an alternative solution, switch cells whose data is null to #N/A.
In this case, Excel will correct the chart automatically.
Given a single cell, I want to know the range of cells that are merged with it.
I have looked at this question:
how to detect merged cells in c# using MS interop excel
But that is to tell you if a given range has merged cells.
There is no Cell type. A single cell is a Range, just like lots of cells.
Therefore the same methods apply: YourCell.MergeCells is a boolean property equal to true for merge ranges and YourCell.MergeArea is the said merged range.
MergeArea always returns a value. If the cell is merged with no other cells, then it returns the cell (again typed Range) itself.
I need to divide two cells in adjacent columns into X equal cells horizontally. I am given a DocumentBuilder, pointing to the cell. I decided that I can insert a separate table into the cell:
var table = builder.StartTable();
builder.InsertCell();
table.AutoFit(AutoFitBehavior.AutoFitToWindow);
builder.Write("1");
builder.EndRow();
builder.InsertCell();
builder.Write("2");
builder.EndRow();
builder.EndTable();
But still, there is a margin on the sides of the inner table:
(ignore the left cell being splitted by horizontal thick line)
I googled that table.AutoFit(AutoFitBehavior.AutoFitToWindow); should solve the problem, but it doesn't. What am I supposed to do, to get desired output:
I managed to split the cell vertically, by setting all other cells in a row cell.CellFormat.VerticalMerge = CellMerge.First, then adding X - 1 rows, in which cells are cell.CellFormat.VerticalMerge = CellMerge.Previous, except cells in columns to de divided.
Using Microsoft Interop for word, after adding a table to the document, how can the column width be set for all columns so that it fits the largest item there? For example, if the column header is only two letters, and each cell underneath is only one digit, the column should only be about a centimeter wide.
If you only have one table in your document, you would use something like this (where oDoc is your active document.)
oDoc.Tables(0).AllowAutoFit = True;
oDoc.Tables(0).AutoFitBehavior(Word.WdAutoFitBehavior.wdAutoFitContent);
If you have more than one table, you'd want to choose the index of the one you wish to update or loop through them.
In the Word object model AutoFit is what the feature is called that allows (or doesn't allow) table columns to resize to fit the content, the width of the window/page or prevents them from resizing automatically.
To force the table columns to resize to fit their content:
tbl.AutoFitBehavior(Word.WdAutoFitBehavior.wdAutoFitContent);
To change the width of a single column to fit to the content:
tbl.Columns[index].AutoFit();
This can also be done for all columns:
tlb.Columns.AutoFit();
I've written a method in C# which loops through an excel range cell by cell, row by row and compare it's (border) colour against the colour I'm looking for. This works - of course - but it is pretty slow...
Is there a possibility I could use the Find method on my range? I googled this but I can't find anything related to finding something else than text.
#Denise I doubt you can use any Find methods on interop to check for cell style. If you're limiting the range already and going cell-by-cell on a foreach, my only advice is to use EPPlus. We were converted when we realized that the speed is increased more than tenfold for sheets with at least 30,000 rows, plus you can use LINQ and no messy interop stuff.
Using EPPlus you would only need to do something like:
//looking for cells with a yellow border on its left side
IEnumerable<ExcelRangeBase> matches = worksheet.Cells.Where(c => c.Style.Border.Left.Color.Rgb == "FFFFFF00");