public void SetColumnWidth(int Column, double Width_, int indTable = -1) { GetTableReference(indTable); MSWord.Columns pColumns = m_pTable.Columns; if (pColumns == null) { return; } int cntColumns = pColumns.Count; if (Column >= 1 && Column <= cntColumns) { MSWord.Column pColumn = pColumns[Column]; if (pColumn == null) { return; } float w = m_pApp.MillimetersToPoints((float)Width_); if (Math.Abs(w) >= 0.009) { pColumn.Width = w; } else { pColumn.Delete(); } //pColumns[Column].SetWidth(w, MSWord.WdRulerStyle.wdAdjustSameWidth); } }
private void Pregunta3() { p1 = "INCORRECTO"; Word.Tables tablas = docAlumno.Tables; if (tablas.Count == 1) { Word.Table tabla = tablas[1]; int filas = tabla.Rows.Count; int columnas = tabla.Columns.Count; if (filas == 6 && columnas == 2 && tabla.Uniform == false) { Word.Cell cell = tabla.Cell(filas, 1); try { Word.Column col = cell.Column; } catch (Exception) { p1 = "CORRECTO"; } } } GuardarPuntaje(); CerrarWords(); BorrarPreguntasTemporales(); }
public void DeleteColumn(int indCol, int indTable) { GetTableReference(indTable); MSWord.Columns pCols = m_pTable.Columns; if (pCols == null) { return; } MSWord.Column pCol = pCols[indCol]; pCol.Delete(); }
public void TableCreateGenre(int row, int col, string[] header, Dictionary <string, double> dictionary) { Object start = 80; Object end = 81; word.Range wordrange = worddocument.Range(ref start, ref end); //wordrange.InsertBreak(word.WdBreakType.wdPageBreak); wordrange.Bold = 400; Object defaultTableBehavior = word.WdDefaultTableBehavior.wdWord9TableBehavior; Object autoFitBehavior = word.WdAutoFitBehavior.wdAutoFitWindow; word.Table wordtable = worddocument.Tables.Add(wordrange, row + 1, col, ref defaultTableBehavior, ref autoFitBehavior); for (int c = 1; c <= col; c++) { word.Range wordcellrange = worddocument.Tables[1].Cell(1, c).Range; wordcellrange.Text = header[c - 1]; } int cellCounter = 2; foreach (var genre in dictionary) { word.Range wordcellrange = worddocument.Tables[1].Cell(cellCounter, 1).Range; wordcellrange.Text = (cellCounter - 1).ToString(); wordcellrange = worddocument.Tables[1].Cell(cellCounter, 2).Range; wordcellrange.Text = genre.Key; wordcellrange = worddocument.Tables[1].Cell(cellCounter, 3).Range; wordcellrange.Text = genre.Value.ToString(); cellCounter++; } wordtable.AllowAutoFit = true; word.Column firstCol = wordtable.Columns[1]; firstCol.AutoFit(); Single firstColAutoWidth = firstCol.Width; wordtable.AutoFitBehavior(word.WdAutoFitBehavior.wdAutoFitWindow); firstCol.SetWidth(firstColAutoWidth, word.WdRulerStyle.wdAdjustFirstColumn); object rEnd = worddocument.Content.End; int rt = (int)rEnd; object rStart = rt - 1; word.Range picRange = worddocument.Range(ref rStart, ref rEnd); picRange.InlineShapes.AddPicture(@"C:\Users\acer\Desktop\Учеба\АИС\Graf.bmp"); }
public void InsertTableCell(int insertBeforeColumnIndex, string cellText, string tableName = "") { if (String.IsNullOrEmpty(tableName)) { object t = _document.Application.Selection.Information[WordOM.WdInformation.wdWithInTable]; var isT = false; Boolean.TryParse(t.ToString(), out isT); if (isT) { WordOM.Table table = _document.Application.Selection.Tables[1]; table.Select(); _document.Application.Selection.InsertCells(WordOM.WdInsertCells.wdInsertCellsEntireColumn); } } else { foreach (WordOM.Table table in _document.Tables) { if (String.Equals(tableName, table.Title, StringComparison.OrdinalIgnoreCase)) { WordOM.Column col = table.Columns[insertBeforeColumnIndex]; col.Select(); _document.Application.Selection.InsertColumnsRight(); table.Columns[table.Columns.Count].Cells[1].Range.Text = cellText; //table.Rows[1].Cells[insertBeforeColumnIndex].Select(); //_document.Application.Selection.InsertCells(); //table.Cell(1, table.Columns.Count).Range.Text = cellText; // table.Columns.Add(table.Columns[insertBeforeColumnIndex]).Cells[insertBeforeColumnIndex + 1].Range.Text = cellText; // table.Rows[1].Cells[2].Select(); // _document.Application.Selection.InsertColumnsRight(); //// _document.Application.Selection.InsertCells(); // table.Cell(1, table.Columns.Count).Range.Text = cellText; } } } }
public void TableCreateBook(int row, int col, string[] header, List <Book> books) { Object start = 94; Object end = 95; word.Range wordrange = worddocument.Range(ref start, ref end); //wordrange.InsertBreak(word.WdBreakType.wdPageBreak); wordrange.Bold = 400; Object defaultTableBehavior = word.WdDefaultTableBehavior.wdWord9TableBehavior; Object autoFitBehavior = word.WdAutoFitBehavior.wdAutoFitWindow; word.Table wordtable = worddocument.Tables.Add(wordrange, row + 1, col, ref defaultTableBehavior, ref autoFitBehavior); for (int c = 1; c <= col; c++) { word.Range wordcellrange = worddocument.Tables[1].Cell(1, c).Range; wordcellrange.Text = header[c - 1]; } for (int i = 0; i < row; i++) { word.Range wordcellrange = worddocument.Tables[1].Cell(i + 2, 1).Range; wordcellrange.Text = $"{books[i].Name} ({books[i].Type})"; wordcellrange = worddocument.Tables[1].Cell(i + 2, 2).Range; wordcellrange.Text = books[i].LitresEstimate.ToString(); wordcellrange = worddocument.Tables[1].Cell(i + 2, 3).Range; wordcellrange.Text = books[i].Description; } wordtable.AllowAutoFit = true; word.Column firstCol = wordtable.Columns[2]; firstCol.AutoFit(); Single firstColAutoWidth = firstCol.Width; wordtable.AutoFitBehavior(word.WdAutoFitBehavior.wdAutoFitWindow); firstCol.SetWidth(firstColAutoWidth, word.WdRulerStyle.wdAdjustFirstColumn); }
public CreateDocument(String [] Section_1, String[] Section_2, String[] Section_3, String[] Section_4, String[] SignaturAndDate) { object oMissing = System.Reflection.Missing.Value; object oEndOfDoc = "\\endofdoc"; /* \endofdoc is a predefined bookmark */ //Start Word and create a new document. Word._Application oWord; Word._Document oDoc; oWord = new Word.Application(); oWord.Visible = false; oDoc = oWord.Documents.Add(ref oMissing, ref oMissing, ref oMissing, ref oMissing); object oRng = oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range; //Section 0: Title Section Word.Paragraph Title_Section; Title_Section = oDoc.Content.Paragraphs.Add(ref oMissing); Title_Section.Range.Font.Size = 16; Title_Section.Range.Bold = 1; Title_Section.Range.Text = "e-Commerce/EDI SI5 Promotion Check List"; Title_Section.Range.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter; Title_Section.Range.InsertParagraphAfter(); //Section 1: User Partner Section--------------------------------------------------------------------------------------------------------- Word.Paragraph UserPartner_Section; UserPartner_Section = oDoc.Content.Paragraphs.Add(ref oMissing); UserPartner_Section.Range.Text = "User: "******"\t\t"); UserPartner_Section.Range.InsertAfter("Partner: " + Section_1[1]); UserPartner_Section.Range.InsertAfter("\t\t"); UserPartner_Section.Range.InsertAfter("Date: " + Section_1[2]); UserPartner_Section.Range.InsertAfter("\n"); UserPartner_Section.Range.InsertAfter("Title: " + Section_1[3]); UserPartner_Section.Range.InsertAfter("\t\t"); UserPartner_Section.Range.InsertAfter("Change Management Request Number: " + Section_1[4]); UserPartner_Section.Range.InsertParagraphAfter(); //Section 2: User Signoff Checklist Section------------------------------------------------------------------------------------------------------ Word.Table UserCheckList; Word.Range wrdRng = oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range; UserCheckList = oDoc.Tables.Add(wrdRng, 10, 4, ref oMissing, ref oMissing); UserCheckList.Range.ParagraphFormat.SpaceAfter = 6; UserCheckList.AllowAutoFit = true; UserCheckList.Columns[1].SetWidth(oWord.CentimetersToPoints(6f), Word.WdRulerStyle.wdAdjustNone); UserCheckList.Range.Font.Size = 10; Word.Column first = UserCheckList.Columns[1]; int checklist = 0; for (int r = 1; r <= 10; r++) { for (int c = 1; c <= 4; c++) { UserCheckList.Cell(r, c).Range.Text = Section_2[checklist]; checklist++; } } //Section 3: User Signoff Checklist Section-------------------------------------------------------------------------------------------------------------- //Insert another paragraph. Word.Paragraph oPara3; oRng = oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range; oPara3 = oDoc.Content.Paragraphs.Add(ref oRng); oPara3.Range.Text = " ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------"; oPara3.Range.Font.Bold = 0; oPara3.Range.Font.Size = 8; oPara3.Range.InsertParagraphAfter(); Word.Table Checklist; wrdRng = oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range; oPara3.Range.Paragraphs.LineSpacing = 10f; Checklist = oDoc.Tables.Add(wrdRng, 15, 4, ref oMissing, ref oMissing); Checklist.Range.ParagraphFormat.SpaceAfter = 6; Checklist.Columns[1].SetWidth(oWord.CentimetersToPoints(5f), Word.WdRulerStyle.wdAdjustNone); Checklist.AllowAutoFit = true; checklist = 0; for (int r = 1; r <= 15; r++) { for (int c = 1; c <= 4; c++) { Checklist.Cell(r, c).Range.Text = Section_3[checklist]; checklist++; } } //Section 4: Schedule //Insert another paragraph. Word.Paragraph oPara4; oRng = oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range; oPara4 = oDoc.Content.Paragraphs.Add(ref oRng); oPara4.Range.Font.Size = 8; oPara4.Range.Text = "--------------------------------------------------------------------------------------------------------------------------------------------------------"; oPara4.Range.Font.Bold = 0; oPara4.Range.InsertParagraphAfter(); Word.Table FinalCheckList; wrdRng = oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range; oPara4.Range.Paragraphs.LineSpacing = 10f; FinalCheckList = oDoc.Tables.Add(wrdRng, 3, 4, ref oMissing, ref oMissing); FinalCheckList.Range.ParagraphFormat.SpaceAfter = 6; FinalCheckList.Columns[1].SetWidth(oWord.CentimetersToPoints(5f), Word.WdRulerStyle.wdAdjustNone); FinalCheckList.AllowAutoFit = true; checklist = 0; for (int r = 1; r <= 3; r++) { for (int c = 1; c <= 4; c++) { FinalCheckList.Cell(r, c).Range.Text = Section_4[checklist]; checklist++; } } //Signature and Date Section //Insert another paragraph. Word.Paragraph SignatureAndDate_Section; oRng = oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range; SignatureAndDate_Section = oDoc.Content.Paragraphs.Add(ref oRng); SignatureAndDate_Section.Range.Font.Bold = 0; SignatureAndDate_Section.Range.InsertParagraphAfter(); SignatureAndDate_Section.Range.Text = "\n\t\t\t\t\t\t\tProject Manager: " + SignaturAndDate[0]; SignatureAndDate_Section.Range.InsertAfter("\n\n"); SignatureAndDate_Section.Range.InsertAfter("\t\t\t\t\t\t\tCompletion Date: " + SignaturAndDate[1]); String filename = @"C:\SharePoint Upload\Checklist_" + Section_2[37].Replace(" ", "") + "_" + DateTime.Now.ToString("yyyyMMdd") + ".docx"; oWord.ActiveDocument.SaveAs2(filename);//Grabs the Implementation from Post Implementation oWord.ActiveDocument.Close(); }