Word Interop: can't group shapes - c#

I create 2 shapes (textbox), then i want to grop it. Shapes are selected but not grouped. I have no idea how to do this...
Here is my code
Word.Application wordapp = new Word.Application();
Word.Document doc = wordapp.Documents.Add();
wordapp.Visible = true;
Word.Shape shNum1 = doc.Shapes.AddTextbox(MsoTextOrientation.msoTextOrientationHorizontal, 100, 100, 10, 10);
shNum1.TextFrame.TextRange.Text = "123";
Word.Shape shNum2 = doc.Shapes.AddTextbox(MsoTextOrientation.msoTextOrientationHorizontal, 150, 150, 10, 10);
shNum2.TextFrame.TextRange.Text = "321";
doc.Shapes.SelectAll();
wordapp.Selection.ShapeRange.Group();

Related

Symbol in added Watermark isn't correctly shown in C# Word Interop

My program has a function to add a watermark to word files, but a symbol 'Ⓒ' is not shown correctly, just a square like the attached file.(it's rotated).
I guess I have to write a line of code to use these symbols, but I cannot find it. Can anybody help me?
if (file.Watermark == true)
{
Microsoft.Office.Interop.Word.Shape wordShape = null;
foreach (Microsoft.Office.Interop.Word.Section section in wordDoc.Sections)
{
wordShape = section.Headers[Microsoft.Office.Interop.Word.WdHeaderFooterIndex.wdHeaderFooterPrimary].Shapes.AddTextEffect(
Microsoft.Office.Core.MsoPresetTextEffect.msoTextEffect1,
"Ⓒ gg", "Arial", (float)30,
Microsoft.Office.Core.MsoTriState.msoTrue,
Microsoft.Office.Core.MsoTriState.msoFalse,
150, 150, ref o);
wordShape.Fill.Visible = Microsoft.Office.Core.MsoTriState.msoTrue;
wordShape.Fill.Solid();
wordShape.Fill.ForeColor.RGB = (Int32)Microsoft.Office.Interop.Word.WdColor.wdColorGray15;
wordShape.Line.Visible = Microsoft.Office.Core.MsoTriState.msoFalse;
wordShape.RelativeHorizontalPosition = Microsoft.Office.Interop.Word.WdRelativeHorizontalPosition.wdRelativeHorizontalPositionMargin;
wordShape.RelativeVerticalPosition = Microsoft.Office.Interop.Word.WdRelativeVerticalPosition.wdRelativeVerticalPositionMargin;
wordShape.Left = 20;
wordShape.Top = 250;
wordShape.Rotation = -45;
}
}
Do something like this :
if (file.Watermark == true)
{
Microsoft.Office.Interop.Word.Shape wordShape = null;
foreach (Microsoft.Office.Interop.Word.Section section in wordDoc.Sections)
{
wordShape = section.Headers[Microsoft.Office.Interop.Word.WdHeaderFooterIndex.wdHeaderFooterPrimary].Shapes.AddTextEffect(
Microsoft.Office.Core.MsoPresetTextEffect.msoTextEffect1,
"\u00a9 gg", "Arial", (float)30,
Microsoft.Office.Core.MsoTriState.msoTrue,
Microsoft.Office.Core.MsoTriState.msoFalse,
150, 150, ref o);
wordShape.Fill.Visible = Microsoft.Office.Core.MsoTriState.msoTrue;
wordShape.Fill.Solid();
wordShape.Fill.ForeColor.RGB = (Int32)Microsoft.Office.Interop.Word.WdColor.wdColorGray15;
wordShape.Line.Visible = Microsoft.Office.Core.MsoTriState.msoFalse;
wordShape.RelativeHorizontalPosition = Microsoft.Office.Interop.Word.WdRelativeHorizontalPosition.wdRelativeHorizontalPositionMargin;
wordShape.RelativeVerticalPosition = Microsoft.Office.Interop.Word.WdRelativeVerticalPosition.wdRelativeVerticalPositionMargin;
wordShape.Left = 20;
wordShape.Top = 250;
wordShape.Rotation = -45;
}
}
you can replace your symbol by this expression :
\u00a9
i thing i will help you
for more informations have a look at this
:
How to use caracter encoding
A similar question has been aked

WPF DocumentViewer show document as byte array

This might be a silly question, but I was wondering if it's possible to display a document in WPF's DocumentViewer control from a byte array.
If not, could someone provide an example of how the control is normally used to display a document? I can't seem to find a decent example.
It is about arranging different UIElements:
FixedDocument fixedDocument = new FixedDocument();
DocumentViewer dv = new DocumentViewer() { Document = fixedDocument };
this.Content = dv;
var page1 = new FixedPage() { Width = 600, Height = 800 };
PageContent page1Content = new PageContent() { Child = page1 };
var sp = new StackPanel();
sp.Children.Add(new TextBlock
{
Text = "Title",
FontSize = 30,
Margin = new Thickness(100, 50, 0, 70)
});
sp.Children.Add(new TextBlock
{
Text = "The quick brown fox jumps over the lazy dog...",
FontSize = 15,
Margin = new Thickness(10, 0, 0, 10)
});
Rectangle rect = new Rectangle();
rect.Width = 150;
rect.Height = 150;
rect.Fill = Brushes.Black;
sp.Children.Add(new Rectangle
{
Width = 150,
Height = 150,
Fill = Brushes.Black
});
page1.Children.Add(sp);
fixedDocument.Pages.Add(page1Content);

C# Microsoft Interop Word put shape inside table cell

I'm trying to put a Microsoft.Office.Interop.Word.Shape inside a table cell like in this short example:
Word.Application oWord = new Microsoft.Office.Interop.Word.Application();
Word.Document oDocument = oWord.Documents.Add();
Word.Table oTable = oDocument.Tables.Add(oDocument.Range(), 4, 1);
Word.Cell oCell1 = oTable.Cell(1,1);
Word.Shape oShape1 = oDocument.Shapes.AddShape(Microsoft.Office.Core.MsoAutoShapeType.msoShapeRectangle.GetHashCode(), 7, 7, 11, 11, oCell1.Range);
Word.Cell oCell2 = oTable.Cell(2, 1);
Word.Shape oShape2 = oDocument.Shapes.AddShape(Microsoft.Office.Core.MsoAutoShapeType.msoShapeRectangle.GetHashCode(), 7, 7, 11, 11, oCell2.Range);
Word.Cell oCell3 = oTable.Cell(3, 1);
Word.Shape oShape3 = oDocument.Shapes.AddShape(Microsoft.Office.Core.MsoAutoShapeType.msoShapeRectangle.GetHashCode(), 7, 7, 11, 11, oCell3.Range);
Word.Cell oCell4 = oTable.Cell(4, 1);
Word.Shape oShape4 = oDocument.Shapes.AddShape(Microsoft.Office.Core.MsoAutoShapeType.msoShapeRectangle.GetHashCode(), 7, 7, 11, 11, oCell4.Range);
oWord.Visible = true;
The rectangle only appears on the top left corner of the document.
I'm not sure what I'm doing wrong since I set the shape anchor to the cells range.
12/07/2016:
Okay, check this out,
I have now 5 columns and 100 rows and try to place the shape into the third column. I'm using the "in line with text" property.
Now, on the first two pages, all the shapes are placed in the first row/column. Starting at the third page it's looking right...
I'm using Office 2013.
Word.Application oWord = new Microsoft.Office.Interop.Word.Application();
Word.Document oDocument = oWord.Documents.Add();
int numRows = 100;
Word.Table oTable = oDocument.Tables.Add(oDocument.Range(), numRows, 5);
oTable.Borders.OutsideLineStyle = Microsoft.Office.Interop.Word.WdLineStyle.wdLineStyleSingle;
oTable.Borders.InsideLineStyle = Microsoft.Office.Interop.Word.WdLineStyle.wdLineStyleSingle;
for (int r = 1; r <= numRows; ++r)
{
Word.Range anchorRange = oTable.Cell(r, 3).Range;
Word.Shape oShape = oDocument.Shapes.AddShape(Microsoft.Office.Core.MsoAutoShapeType.msoShapeRectangle.GetHashCode(), 7, 7, 11, 11, anchorRange);
oShape.WrapFormat.Type = Microsoft.Office.Interop.Word.WdWrapType.wdWrapInline;
}
oWord.Visible = true;
If you click on the rectangle that's added, and enable paragraph/formatting symbols (it's the backwards P looking button in Home > Paragraph), you'll notice that the anchors are indeed on the table cells. Text-wrapped shapes also need other settings to have certain positions on the page. Mess with the Size and Position dialog to get a feel for it.

NSAttributedString not working on UITextField ios xamarin

I'm having trouble changing the font and fontsize of a placeholder inside a UITextField.
this.emailTextField = new UITextField ();
//Not working
this.emailTextField.AttributedPlaceholder = new NSAttributedString ("Email address", UIFont.FromName("Didot-Italic", 6.0f));
this.emailTextField.KeyboardType = UIKeyboardType.EmailAddress;
this.emailTextField.ReturnKeyType = UIReturnKeyType.Next;
this.emailTextField.AdjustsFontSizeToFitWidth = true;
this.emailTextField.ClearButtonMode = UITextFieldViewMode.Always;
this.emailTextField.BackgroundColor = UIColor.White;
this.emailTextField.BorderStyle = UITextBorderStyle.None;
var bottomLayer = new CALayer ();
bottomLayer.BorderColor = UIColor.Black.CGColor;
bottomLayer.BorderWidth = 1;
bottomLayer.Frame = new RectangleF (0, 29, 200, 1);
this.emailTextField.Layer.AddSublayer (bottomLayer);
this.emailTextField.Frame = new RectangleF (60, this.fbButton.Frame.Bottom + 20, 200, 30);
You could try to use it like below. It worked me so far.
this.emailTextField.AttributedPlaceholder = new NSAttributedString ("Email address", new UIStringAttributes{Font = UIFont.FromName("Didot-Italic", 6.0f)});

Excel charts +C#

I am using excel to draw charts from c#, but i need the chart to be one series related to each other not two series (when i select a range that has two columns of data)
can any one help:
xla.Visible = true;
Workbook wb = xla.Workbooks.Add(XlSheetType.xlWorksheet);
Worksheet ws = (Worksheet)xla.ActiveSheet;
// Now create the chart.
ChartObjects chartObjs = (ChartObjects)ws.ChartObjects(Type.Missing);
ChartObject chartObj = chartObjs.Add(100, 20, 300, 300);
Chart xlChart = chartObj.Chart;
Range rg = ws.get_Range("B2", "C17");
xlChart.SetSourceData(chartRange, XlRowCol.xlColumns);
thanks
I cleaned the code up a bit and added the generation of random data so this should run on its own.
Random random = new Random();
Microsoft.Office.Interop.Excel.Application xla = new Microsoft.Office.Interop.Excel.Application();
xla.Visible = true;
Workbook wb = xla.Workbooks.Add(XlSheetType.xlWorksheet);
Worksheet ws = (Worksheet)xla.ActiveSheet;
// Now create the chart.
ChartObjects chartObjs = (ChartObjects)ws.ChartObjects();
ChartObject chartObj = chartObjs.Add(150, 20, 300, 300);
Chart xlChart = chartObj.Chart;
// generate some random data
for (int row = 0; row < 16; row++)
{
ws.Cells[row + 2, 2] = row + 1;
ws.Cells[row + 2, 3] = random.Next(100);
}
Range xValues = ws.Range["B2", "B17"];
Range values = ws.Range["C2", "C17"];
SeriesCollection seriesCollection = xlChart.SeriesCollection();
Series series1 = seriesCollection.NewSeries();
series1.XValues = xValues;
series1.Values = values;

Categories

Resources