Exemplo n.º 1
0
        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();
        }
Exemplo n.º 2
0
        public void DeleteRowInTable(int indTable, int index)
        {
            if (m_pApp != null)
            {
                if (m_pDoc == null)
                {
                    m_pDoc = m_pApp.ActiveDocument;
                }
                if (m_pDoc == null)
                {
                    return;
                }

                MSWord.Tables tables = m_pDoc.Tables;
                if (tables.Count == 0)
                {
                    return;
                }

                m_pTable = tables[indTable];
                if (m_pTable == null)
                {
                    return;
                }

                m_pTable.Rows[index].Delete();
            }
        }
Exemplo n.º 3
0
        public void SyncTable()
        {
            // var doc = new OfficeDocument(Globals.ThisAddIn.Application.ActiveDocument);
            //var proptectionType = -1;
            try
            {
                //proptectionType = doc.TurnOffProtection(String.Empty);


                WordOM.Tables tables = Globals.ThisAddIn.Application.Selection.Tables;
                if (tables == null || tables.Count == 0)
                {
                    MessageBox.Show(@"Please ensure your cursor is within a table", @"No Table Found", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }

                WordOM.Table table = tables[1];


                WordOM.ContentControls contentcontrols = table.Range.ContentControls;
                if (contentcontrols == null)
                {
                    return;
                }

                foreach (WordOM.ContentControl contentControl in contentcontrols)
                {
                    if (String.IsNullOrEmpty(contentControl.Tag))
                    {
                        continue;
                    }

                    WordOM.ContentControls matchingControls =
                        Globals.ThisAddIn.Application.ActiveDocument.SelectContentControlsByTag(contentControl.Tag);
                    foreach (WordOM.ContentControl mc in matchingControls)
                    {
                        mc.Range.Text = contentControl.Range.Text;
                    }
                }
            }
            catch (Exception e)
            {
                var logger = new EventViewerLogger();
                logger.Log(e.ToString(), Type.Error);

#if DEBUG
                MessageBox.Show(e.ToString(), @"sorry");
#endif
            }
        }
Exemplo n.º 4
0
        private void FormatAllTables(string DocToFormat)
        {
            var application = new Word.Application();

            Word.Document document = application.Documents.Open(DocToFormat);

            int PCount = document.Content.Tables.Count;

            Word.Tables tables = document.Tables;
            Word.Table  table;

            if (PCount > 0)
            {
                for (int i = 1; i <= document.Content.Tables.Count; i++)
                {
                    lblProcessing.Text = "Processing All Tables...";
                    table = tables[i];
                    int cols = table.Columns.Count;
                    for (int ii = 1; ii < table.Columns.Count + 1; ii++)
                    {
                        Word.Cell cell = table.Cell(1, ii);

                        cell.Range.Font.Color = Word.WdColor.wdColorWhite;
                        cell.Range.Font.Size  = 11;
                        cell.Range.Font.Name  = "Arial";
                        cell.Range.Bold       = 1;
                    }
                    int rows = table.Rows.Count;
                    for (int r = 2; r < table.Rows.Count + 1; r++)
                    {
                        for (int ii = 1; ii < table.Columns.Count + 1; ii++)
                        {
                            Word.Cell cell = table.Cell(r, ii);

                            cell.Range.Font.Color = Word.WdColor.wdColorBlack;
                            cell.Range.Font.Size  = 11;
                            cell.Range.Font.Name  = "Arial";
                            cell.Range.Bold       = 1;
                        }
                    }
                }
            }
            document.Save();
            document.Close();
            application.Quit();
        }
Exemplo n.º 5
0
 /// <summary>
 /// 构造函式,使用模板
 /// </summary>
 /// <param name="template"></param>
 public WordReport(string template)
 {
     try
     {
         _defaultFont = new WordFont();
         _engine      = new Word.Application();
         _wordDoc     = _engine.Documents.Open(template, _missing, _missing, _missing, _missing, _missing, _missing, _missing, _missing, _missing, _missing, _missing, _missing, _missing, _missing, _missing);
         _wordTables  = _wordDoc.Tables;
         _wordShapes  = _wordDoc.InlineShapes;
         _version     = DetermineVersion();
         _chartStyle  = new WordChartStyle();
     }
     catch (Exception ex)
     {
         ErrorParser(ex);
         return;
     }
 }
Exemplo n.º 6
0
        public void InsertRowsInTable(int indTable, int nCount)
        {
            if (nCount <= 0)
            {
                return;
            }

            if (m_pApp != null)
            {
                if (m_pDoc == null)
                {
                    m_pDoc = m_pApp.ActiveDocument;
                }
                if (m_pDoc == null)
                {
                    return;
                }

                MSWord.Tables tables = m_pDoc.Tables;
                if (tables.Count == 0)
                {
                    return;
                }

                m_pTable = tables[indTable];
                if (m_pTable == null)
                {
                    return;
                }

                m_pTable.Select();

                MSWord.Selection pSel = m_pApp.Selection;
                pSel.InsertRowsBelow(nCount);

                m_pDoc.Select();
                m_pSelection = m_pApp.Selection;
                if (m_pSelection == null)
                {
                    return;
                }
                m_pSelection.Collapse(0);
            }
        }
Exemplo n.º 7
0
        private void Pregunta2()
        {
            bool tablaEsCorrecto    = false;
            bool posicionEsCorrecto = false;

            p1 = "INCORRECTO";

            Word.Tables tablas = docAlumno.Tables;
            if (tablas.Count == 1) //comprobar que exista solo una tabla
            {
                /******************** Comprobar si la Tabla es correcta ******************/
                int filas    = tablas[1].Rows.Count;
                int columnas = tablas[1].Columns.Count;
                if (filas == 3 && columnas == 4)
                {
                    tablaEsCorrecto = true;
                }
                /*************************************************************************/

                /********comprobar la pisicion de la tabla*****/
                Word.Range rango   = tablas[1].Range;
                int        numPage = tablas[1].Range.get_Information(Word.WdInformation.wdActiveEndPageNumber); //pagina donde se encuentra la tabla

                int start = rango.Start;
                int end   = rango.End;
                if (start >= 345 && start <= 355 && end >= 360 && end <= 370 && numPage == 1)
                {
                    posicionEsCorrecto = true;
                }
                /*************************************************************************/

                if (tablaEsCorrecto && posicionEsCorrecto)
                {
                    p1 = "CORRECTO";
                }
            }

            GuardarPuntaje();
            CerrarWords();

            BorrarPreguntasTemporales();
        }
Exemplo n.º 8
0
        private void Pregunta9()
        {
            p1 = "INCORRECTO";
            Word.Tables tablas = docAlumno.Tables;
            if (tablas.Count == 1)
            {
                Word.Style estilo = tablas[1].get_Style();

                //Claves del éxito
                string cadenaAchequear    = "Tabla de cuadrícula 2 - Énfasis 4";
                string contenidoDeArchivo = estilo.NameLocal;

                if (contenidoDeArchivo.Equals(cadenaAchequear))
                {
                    p1 = "CORRECTO";
                }
            }

            GuardarPuntaje();
            CerrarWords();

            BorrarPreguntasTemporales();
        }
Exemplo n.º 9
0
        private void Pregunta4()
        {
            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;

                Word.Columns col = tabla.Columns;

                if (filas == 5 && columnas == 2 && col.Last.Width == col.First.Width)
                {
                    p1 = "CORRECTO";
                }
            }

            GuardarPuntaje();
            CerrarWords();

            BorrarPreguntasTemporales();
        }
Exemplo n.º 10
0
        private void Pregunta8()
        {
            p1 = "INCORRECTO";

            Word.Tables tablas = docAlumno.Tables;
            if (tablas.Count == 1)
            {
                //Claves del éxito
                string cadenaAchequear    = "Claves de éxito";
                string contenidoDeArchivo = tablas[1].Title;
                if (!String.IsNullOrEmpty(contenidoDeArchivo))
                {
                    if (contenidoDeArchivo.Equals(cadenaAchequear))
                    {
                        p1 = "CORRECTO";
                    }
                }
            }

            GuardarPuntaje();
            CerrarWords();

            BorrarPreguntasTemporales();
        }
Exemplo n.º 11
0
        public void GetTableReference(int indTable)
        {
            if (indTable == -1)
            {
                if (m_pDoc == null)
                {
                    m_pDoc = m_pApp.ActiveDocument;
                }
                if (m_pDoc == null)
                {
                    return;
                }

                MSWord.Tables tables = m_pDoc.Tables;
                if (tables.Count == 0)
                {
                    return;
                }

                m_pTable = tables[m_pDoc.Tables.Count];
                if (m_pTable == null)
                {
                    return;
                }

                old_table_index = tables.Count;
                return;
            }

            if (indTable != old_table_index)
            {
                if (m_pDoc == null)
                {
                    m_pDoc = m_pApp.ActiveDocument;
                }
                if (m_pDoc == null)
                {
                    return;
                }

                MSWord.Tables tables = m_pDoc.Tables;
                if (tables.Count == 0 || tables.Count < indTable)
                {
                    return;
                }

                m_pTable = tables[indTable];
                if (m_pTable == null)
                {
                    return;
                }

                old_table_index = indTable;
                return;
            }

            if (m_pTable == null)
            {
                if (m_pDoc == null)
                {
                    m_pDoc = m_pApp.ActiveDocument;
                }
                if (m_pDoc == null)
                {
                    return;
                }

                MSWord.Tables tables = m_pDoc.Tables;
                if (tables.Count == 0)
                {
                    return;
                }

                m_pTable = tables[tables.Count];
                if (m_pTable == null)
                {
                    return;
                }

                old_table_index = tables.Count;
                return;
            }
        }
Exemplo n.º 12
0
		/// <summary>
		/// Word operation
		/// </summary>
		/// <param name="command"></param>
		/// <param name="sArg"></param>
		/// <param name="nArg1"></param>
		/// <param name="nArg2"></param>
		/// <param name="nArg3"></param>
		/// <param name="nArg4"></param>
		/// <returns></returns>
		public static string Call(
			string command,
			string sArg,
			int nArg1,
			int nArg2,
			int nArg3,
			int nArg4,
			bool bArg)
		{

			object missingObj = System.Reflection.Missing.Value; // missing object parameter 

			if (SS.I.DebugFlags[5] != null) // dump out command for debug
			{
				ClientLog.Message("Call " + command + " " + sArg);
			}

			try // catch any Word exception
			{

				//******************************************************************************  
				if (Lex.Eq(command, "CreateObject"))  // create the word object
				//******************************************************************************  
				{
					try
					{
						WdApp = new Microsoft.Office.Interop.Word.Application();
					}
					catch (Exception ex)
					{
						return "Word failed to start";
					}

				}

		//******************************************************************************  
				else if (Lex.Eq(command, "Quit"))
				{ // quit application
					//******************************************************************************  

					//Microsoft.Office.Interop.Word.Application.
					WdApp.Quit(ref missingObj, ref missingObj, ref missingObj);

					//	AutoWrap(DISPATCH_METHOD, NULL, WdApp, L"Quit", 0);
				}

			//******************************************************************************  
				else if (Lex.Eq(command, "Cells.SetWidth"))
				{
					//******************************************************************************  
					WdSel.Cells.SetWidth(nArg1, WdRulerStyle.wdAdjustNone);
#if false
	release_obj(WdTemp); // get current font object
	AutoWrap(DISPATCH_PROPERTYGET, &result, WdSel, L"Cells", 0);
	WdTemp = result.pdispVal;

	SETLONG(Arg1,nArg1);  // width in points
	SETLONG(Arg2,wdAdjustNone); // ruler style, required sArg
	AutoWrap(DISPATCH_METHOD, &result, WdTemp, L"Setwidth", 2, Arg2, Arg1);
	VariantClear(&Arg1);
	VariantClear(&Arg2);
#endif
				}

			//******************************************************************************  
				else if (Lex.Eq(command, "DeleteObject"))
				{
					//******************************************************************************  
					WdSel = null;
					WdTable = null;
					WdTables = null;
					WdDoc = null;
					WdDocs = null;
					WdApp = null;
#if false
	// Release references, must do lower to higher level...
	release_obj(WdTemp);
	release_obj(WdSel);
	release_obj(WdTable);
	release_obj(WdTables);
	release_obj(WdDoc);
	release_obj(WdDocs);
	release_obj(WdApp);
#endif
				}

			//******************************************************************************  
				else if (Lex.Eq(command, "Close"))
				{
					//******************************************************************************  
					//      excelobj.ActiveWorkbook.Close False ' no prompt for save
					((_Document)WdDoc).Close(ref missingObj, ref missingObj, ref missingObj);

					//	SETLONG(SaveChanges,wdSaveChanges); // don't prompt
					//	AutoWrap(DISPATCH_METHOD, NULL, WdDoc, L"Close", 1, SaveChanges);
					//	VariantClear(&SaveChanges);
				}

			//******************************************************************************  
				else if (Lex.Eq(command, "Documents.Add"))
				{ // Add a new document
					//******************************************************************************  

					WdDocs = WdApp.Documents;
					WdDoc = WdDocs.Add(ref missingObj, ref missingObj, ref missingObj, ref missingObj);

#if false
	release_obj(WdDocs); // Get active documents
	AutoWrap(DISPATCH_PROPERTYGET, &result, WdApp, L"Documents", 0);   // Get Documents collection
	WdDocs = result.pdispVal;

	release_obj(WdDoc); // Add new document
	AutoWrap(DISPATCH_METHOD, &result, WdDocs, L"Add", 0);
	WdDoc = result.pdispVal;
#endif

					if (WdDoc == null) return ("Error adding document");
					UpdateSelection(); // update selection
				}

			//******************************************************************************  
				else if (Lex.Eq(command, "EndKey"))
				{
					//******************************************************************************  
					Object unit = nArg1;
					WdSel.HomeKey(ref unit, ref missingObj);

					//	SETLONG(Arg,nArg1); 
					//	AutoWrap(DISPATCH_METHOD, &result, WdSel, L"HomeKey", 1, Arg);
					//	VariantClear(&Arg);

					UpdateSelection(); // update selection
				}

			//******************************************************************************  
				else if (Lex.Eq(command, "Font.Name"))
				{
					//******************************************************************************  
					//      WordObj.Selection.Font.Name = sArg
					WdSel.Font.Name = sArg;

#if false
	release_obj(WdTemp); // get current font object
	AutoWrap(DISPATCH_PROPERTYGET, &result, WdSel, L"Font", 0);
	WdTemp = result.pdispVal;

	SETSTR(Arg,sArg);  // set font name
	AutoWrap(DISPATCH_PROPERTYPUT, &result, WdTemp, L"Name", 1, Arg);
	VariantClear(&Arg);
#endif
				}

			//******************************************************************************  
				else if (Lex.Eq(command, "Font.Size"))
				{
					//******************************************************************************  
					//      WordObj.Selection.Font.Size = sArg

					WdSel.Font.Size = nArg1;

#if false
	release_obj(WdTemp); // get current font object
	AutoWrap(DISPATCH_PROPERTYGET, &result, WdSel, L"Font", 0);
	WdTemp = result.pdispVal;

	SETLONG(Arg,nArg1);  // set font size
	AutoWrap(DISPATCH_PROPERTYPUT, &result, WdTemp, L"Size", 1, Arg);
	VariantClear(&Arg);
#endif
				}

			//******************************************************************************  
				else if (Lex.Eq(command, "Font.Bold"))
				//******************************************************************************  
				{
					if (bArg) WdSel.Font.Bold = -1;
					else WdSel.Font.Bold = 0;
				}

	//******************************************************************************  
				else if (Lex.Eq(command, "Font.Italic"))
				//******************************************************************************  
				{
					if (bArg) WdSel.Font.Italic = -1;
					else WdSel.Font.Italic = 0;
				}

		//******************************************************************************  
				else if (Lex.Eq(command, "Font.Subscript"))
				//******************************************************************************  
				{
					WdSel.Font.Subscript = nArg1;

#if false
	release_obj(WdTemp); // get current font object
	AutoWrap(DISPATCH_PROPERTYGET, &result, WdSel, L"Font", 0);
	WdTemp = result.pdispVal;

	SETLONG(Arg,nArg1);  // set font size
	AutoWrap(DISPATCH_PROPERTYPUT, &result, WdTemp, L"Subscript", 1, Arg);
	VariantClear(&Arg);
#endif
				}

			//******************************************************************************  
				else if (Lex.Eq(command, "Font.Superscript"))
				{
					//******************************************************************************  
					WdSel.Font.Superscript = nArg1;

#if false
	release_obj(WdTemp); // get current font object
	AutoWrap(DISPATCH_PROPERTYGET, &result, WdSel, L"Font", 0);
	WdTemp = result.pdispVal;

	SETLONG(Arg,nArg1);  // set font size
	AutoWrap(DISPATCH_PROPERTYPUT, &result, WdTemp, L"Superscript", 1, Arg);
	VariantClear(&Arg);
#endif
				}

			//******************************************************************************  
				else if (Lex.Eq(command, "SetDefaultCellStyle"))
				//******************************************************************************  
				{ // Cell style (e.g. backcolor) automatically carries down do successive
					// rows and must be explicitly reset

					//			int rgbBlack = 0;
					//			if (WdSel.Font.Color != (Microsoft.Office.Interop.Word.WdColor)rgbBlack)
					//				WdSel.Font.Color = (Microsoft.Office.Interop.Word.WdColor)rgbBlack;

					//			int rgbWhite = 255 + 255 * 256 + 255 * 65536;
					//			if (WdSel.Cells.Shading.BackgroundPatternColor != (Microsoft.Office.Interop.Word.WdColor)rgbWhite)
					//				WdSel.Cells.Shading.BackgroundPatternColor = (Microsoft.Office.Interop.Word.WdColor)rgbWhite;

					if (WdSel.Font.Color != Microsoft.Office.Interop.Word.WdColor.wdColorAutomatic)
						WdSel.Font.Color = Microsoft.Office.Interop.Word.WdColor.wdColorAutomatic;

					if (WdSel.Cells.Shading.BackgroundPatternColor != Microsoft.Office.Interop.Word.WdColor.wdColorAutomatic)
						WdSel.Cells.Shading.BackgroundPatternColor = Microsoft.Office.Interop.Word.WdColor.wdColorAutomatic;
				}

			//******************************************************************************  
				else if (Lex.Eq(command, "Font.Color"))
				//******************************************************************************  
				{
					Color c = Color.FromArgb(nArg1);
					int rgb = c.R + c.G * 256 + c.B * 65536;
					WdSel.Font.Color = (Microsoft.Office.Interop.Word.WdColor)rgb;
				}

			//******************************************************************************  
				else if (Lex.Eq(command, "BackColor"))
				//******************************************************************************  
				{
					Color c = Color.FromArgb(nArg1);
					int rgb = c.R + c.G * 256 + c.B * 65536;
					WdSel.Cells.Shading.BackgroundPatternColor = (Microsoft.Office.Interop.Word.WdColor)rgb;
				}

		//******************************************************************************  
				else if (Lex.Eq(command, "HomeKey"))
				{
					//******************************************************************************  
					Object unit = nArg1;
					WdSel.HomeKey(ref unit, ref missingObj);
#if false
	SETLONG(Arg,nArg1); 
	AutoWrap(DISPATCH_METHOD, &result, WdSel, L"HomeKey", 1, Arg);
	VariantClear(&Arg);
#endif
					UpdateSelection(); // update selection
				}

			//******************************************************************************  
				else if (Lex.Eq(command, "InlineShapes.AddPicture"))
				{ // insert image from file
					//******************************************************************************  
					InlineShape ils = WdSel.InlineShapes.AddPicture(sArg, ref missingObj, ref missingObj, ref missingObj);
					ils.Width = nArg1;
					ils.Height = nArg2;
#if false
	release_obj(WdTemp); // get current font object
	AutoWrap(DISPATCH_PROPERTYGET, &result, WdSel, L"InlineShapes", 0);
	WdTemp = result.pdispVal;

	SETSTR(Filename,sArg);  // filename
	SETLONG(Width,nArg1); // in points
	SETLONG(Height,nArg2);

	AutoWrap(DISPATCH_METHOD, &result, WdTemp, L"AddPicture", 1, Filename);
	release_obj(WdTemp);
	WdTemp = result.pdispVal; // new shape object

	AutoWrap(DISPATCH_PROPERTYPUT, NULL, WdTemp, L"Width", 1, Width);

	AutoWrap(DISPATCH_PROPERTYPUT, NULL, WdTemp, L"Height", 1, Height);

	VariantClear(&Filename);
	VariantClear(&Width);
	VariantClear(&Height);
#endif
				}

			//******************************************************************************  
				else if (Lex.Eq(command, "InsertBreak"))
				{
					//******************************************************************************  
					object type = nArg1;
					WdSel.InsertBreak(ref type);

					//	SETLONG(Arg,nArg1); 
					//	AutoWrap(DISPATCH_METHOD, &result, WdSel, L"InsertBreak", 1, Arg);
					//	VariantClear(&Arg);

					UpdateSelection(); // update selection
				}

			//******************************************************************************  
				else if (Lex.Eq(command, "InsertSymbol"))
				{
					//******************************************************************************  
					// InsertSymbol(CharacterNumber as Long, Font as String)
					int characterNumber = nArg1;
					object font = sArg;
					WdSel.InsertSymbol(characterNumber, ref font, ref missingObj, ref missingObj);
#if false
	SETLONG(Arg,nArg1); // get char number
	SETSTR(Arg2,sArg); // get font
	AutoWrap(DISPATCH_METHOD, &result, WdSel, L"InsertSymbol", 2, Arg2, Arg);
	VariantClear(&Arg);
	VariantClear(&Arg2);
#endif
				}

			//******************************************************************************  
				else if (Lex.Eq(command, "Cells.Merge"))
				{ // merge cells together
					//******************************************************************************  
					WdSel.Cells.Merge();
#if false
	release_obj(WdTemp); // get current font object
	AutoWrap(DISPATCH_PROPERTYGET, &result, WdSel, L"Cells", 0);
	WdTemp = result.pdispVal;

	AutoWrap(DISPATCH_METHOD, &result, WdTemp, L"Merge", 0);
#endif
				}

			//******************************************************************************  
				else if (Lex.Eq(command, "MoveLeft"))
				{ // units, count
					//******************************************************************************  
					if (nArg2 <= 0) nArg2 = 1;

					object unit = nArg1;
					object count = nArg2;
					WdSel.MoveLeft(ref unit, ref count, ref missingObj);
#if false
	SETLONG(Arg1,nArg1); 
	SETLONG(Arg2,nArg2); 
	AutoWrap(DISPATCH_METHOD, &result, WdSel, L"MoveLeft", 2, Arg2, Arg1);
	VariantClear(&Arg1);
	VariantClear(&Arg2);
#endif
					UpdateSelection(); // update selection
				}

			//******************************************************************************  
				else if (Lex.Eq(command, "MoveRight"))
				{ // units, count, extend
					//******************************************************************************  
					object extend;
					if (nArg2 <= 0) nArg2 = 1;

					object unit = nArg1;
					object count = nArg2;
					if (nArg3 <= 0) extend = missingObj;
					else extend = nArg3;

					WdSel.MoveRight(ref unit, ref count, ref extend);
#if false
	SETLONG(Arg1,nArg1); 
	SETLONG(Arg2,nArg2); 
	SETLONG(Arg3,nArg3); 
	AutoWrap(DISPATCH_METHOD, &result, WdSel, L"MoveRight", 3, Arg3, Arg2, Arg1);
	VariantClear(&Arg1);
	VariantClear(&Arg2);
	VariantClear(&Arg3);
#endif

					UpdateSelection(); // update selection
				}

			//******************************************************************************  
				else if (Lex.Eq(command, "MoveDown"))
				{ // units, count
					//******************************************************************************  
					if (nArg2 <= 0) nArg2 = 1;
					object unit = nArg1;
					object count = nArg2;
					WdSel.MoveDown(ref unit, ref count, ref missingObj);
#if false
	SETLONG(Arg1,nArg1); 
	SETLONG(Arg2,nArg2); 
	AutoWrap(DISPATCH_METHOD, &result, WdSel, L"MoveDown", 2, Arg2, Arg1);
	VariantClear(&Arg1);
	VariantClear(&Arg2);
#endif
					UpdateSelection(); // update selection
				}

			//******************************************************************************  
				else if (Lex.Eq(command, "MoveUp"))
				{ // units, count
					//******************************************************************************  
					if (nArg2 <= 0) nArg2 = 1;
					object unit = nArg1;
					object count = nArg2;
					WdSel.MoveUp(ref unit, ref count, ref missingObj);
#if false
	SETLONG(Arg1,nArg1); 
	SETLONG(Arg2,nArg2); 
	AutoWrap(DISPATCH_METHOD, &result, WdSel, L"MoveUp", 2, Arg2, Arg1);
	VariantClear(&Arg1);
	VariantClear(&Arg2);
#endif

					UpdateSelection(); // update selection
				}

			//******************************************************************************  
				else if (Lex.Eq(command, "PageSetup.Orientation"))
				{
					//******************************************************************************  

					if (nArg1 == 0)
						WdSel.PageSetup.Orientation = WdOrientation.wdOrientPortrait;
					WdSel.PageSetup.Orientation = WdOrientation.wdOrientLandscape;
#if false
	release_obj(WdTemp);
	AutoWrap(DISPATCH_PROPERTYGET, &result, WdSel, L"PageSetup", 0);
	WdTemp = result.pdispVal;

	SETLONG(Arg,nArg1); 
	AutoWrap(DISPATCH_PROPERTYPUT, &result, WdTemp, L"Orientation", 1, Arg);
	VariantClear(&Arg);
#endif
				}

			//******************************************************************************  
				else if (Lex.Eq(command, "PageSetup.Margins"))
				{
					//******************************************************************************  
					WdSel.PageSetup.TopMargin = nArg1;
					WdSel.PageSetup.BottomMargin = nArg2;
					WdSel.PageSetup.LeftMargin = nArg3;
					WdSel.PageSetup.RightMargin = nArg4;
				}

			//******************************************************************************  
				else if (Lex.Eq(command, "PageSetup.PageSize"))
				{
					//******************************************************************************  
					WdSel.PageSetup.PageWidth = nArg1;
					WdSel.PageSetup.PageHeight = nArg2;
				}

			//******************************************************************************  
				else if (Lex.Eq(command, "ParagraphFormat.Alignment"))
				{
					//******************************************************************************  
					WdSel.ParagraphFormat.Alignment = (WdParagraphAlignment)nArg1;
				}

			//******************************************************************************  
				else if (Lex.Eq(command, "Cells.VerticalAlignment"))
				//******************************************************************************  
				{
					WdSel.Cells.VerticalAlignment = (WdCellVerticalAlignment)nArg1;
				}

		//******************************************************************************  
				else if (Lex.Eq(command, "Paste"))
				//******************************************************************************  
				{
					WdSel.Paste();
				}

			//******************************************************************************  
				else if (Lex.Eq(command, "PasteSpecial"))
				{
					//******************************************************************************  
					//	PasteSpecial(IconIndex, Link, Placement, DisplayAsIcon, DataType)

					object iconIndex = 0;
					object link = false;
					object placement = InLine;
					object displayAsIcon = false;
					object dataType = nArg1; // set type of data to paste

					//	ClientLog.Message("Before PasteSpecial"); // TST & PRD 
					WdSel.PasteSpecial(ref iconIndex, ref link, ref placement, ref displayAsIcon,
						ref dataType, ref missingObj, ref missingObj);
					//	ClientLog.Message("After PasteSpecial");
				}

			//******************************************************************************  
				else if (Lex.Eq(command, "InsertStructure"))
				//******************************************************************************  
				// Selection.InlineShapes.AddOLEObject ClassType:="ISISServer", FileName:= _
				//  "C:\Isis\sketch1-small.skc", LinkToFile:=False, DisplayAsIcon:=False
				// This is significantly slower than a paste
				{
					object classType = "ISISServer";
					object fileName = sArg;

					WdSel.InlineShapes.AddOLEObject(
						ref classType,
						ref fileName,
						ref missingObj,
						ref missingObj,
						ref missingObj,
						ref missingObj,
						ref missingObj,
						ref missingObj);
				}

			//******************************************************************************  
				else if (Lex.Eq(command, "Rows.AllowBreakAcrossPages"))
				{ // keep all contents of row on same page
					//******************************************************************************  

					WdSel.Rows.AllowBreakAcrossPages = nArg1;
				}

		//******************************************************************************  
				else if (Lex.Eq(command, "Rows.HeadingFormat"))
				{ // mark rows as headings
					//******************************************************************************  

					WdSel.Rows.HeadingFormat = nArg1;
				}

		//******************************************************************************  
				else if (Lex.Eq(command, "SaveAs"))
				{ // save file in .doc format
					//******************************************************************************  
					try { File.Delete(sArg); } // delete any existing file
					catch (Exception ex) { };
					object fileName = sArg;
					object fileFormat = WdSaveFormat.wdFormatDocument;

					WdDoc.SaveAs(
						ref fileName, // FileName 
						ref fileFormat, // FileFormat 
						ref missingObj, // LockComments 
						ref missingObj, // Password 
						ref missingObj, // AddToRecentFiles 
						ref missingObj, // WritePassword 
						ref missingObj, // ReadOnlyRecommended 
						ref missingObj, // EmbedTrueTypeFonts 
						ref missingObj, // SaveNativePictureFormat
						ref missingObj,	// SaveFormsData 
						ref missingObj,	// SaveAsAOCELetter
						ref missingObj,	// Encoding
						ref missingObj,	// InsertLineBreaks 
						ref missingObj, // AllowSubstitutions 
						ref missingObj, // LineEnding 
						ref missingObj); // AddBiDiMarks
				}

		//******************************************************************************  
				else if (Lex.Eq(command, "ScreenUpdating"))
				{
					//******************************************************************************  
					WdApp.ScreenUpdating = bArg;
				}

		//******************************************************************************  
				else if (Lex.Eq(command, "SelectColumn"))
				{ // select current column of table
					//******************************************************************************  
					WdSel.SelectColumn();
					//	AutoWrap(DISPATCH_METHOD, NULL, WdSel, L"SelectColumn", 0); 
					UpdateSelection();
				}

				//******************************************************************************  
				else if (Lex.Eq(command, "SelectRow"))
				{ // select current row of table
					//******************************************************************************  
					WdSel.SelectRow();

					UpdateSelection();
				}

				//******************************************************************************  
				else if (Lex.Eq(command, "Tables.Add"))
				{ // number of rows & cols supplied
					//******************************************************************************  

					WdTables = WdDoc.Tables;
					Microsoft.Office.Interop.Word.Range range = WdSel.Range;
					int numRows = nArg1;
					int numCols = nArg2;
					WdTable = WdTables.Add(range, numRows, numCols, ref missingObj, ref missingObj);
					WdTable.Borders.InsideLineStyle = WdLineStyle.wdLineStyleSingle;
					WdTable.Borders.OutsideLineStyle = WdLineStyle.wdLineStyleSingle;

					UpdateSelection();
				}

				//******************************************************************************  
				else if (Lex.Eq(command, "TableSelect"))
				{
					//******************************************************************************  

					WdTable.Select();

					UpdateSelection(); // update selection
				}

				//******************************************************************************  
				else if (Lex.Eq(command, "TypeParagraph"))
				{
					//******************************************************************************  
					WdSel.TypeParagraph();

					UpdateSelection();
				}

				//******************************************************************************  
				else if (Lex.Eq(command, "TypeText"))
				{
					//******************************************************************************  
					WdSel.TypeText(sArg);
					//	SETSTR(Arg,sArg); 
					//	AutoWrap(DISPATCH_METHOD, &result, WdSel, L"TypeText", 1, Arg);
					//	VariantClear(&Arg);

					UpdateSelection();
				}

				//******************************************************************************  
				else if (Lex.Eq(command, "Visible"))
				{
					//******************************************************************************  
					WdApp.Visible = bArg;
#if false
	SETBOOL(True,1);
	SETBOOL(False,0);
	if (strcmpi((CCP)sArg,"true)) 
	AutoWrap(DISPATCH_PROPERTYPUT, NULL, WdApp, L"Visible", 1, True);

	else 	AutoWrap(DISPATCH_PROPERTYPUT, NULL, WdApp, L"Visible", 1, False);
#endif
				}

		//******************************************************************************  
				else throw new Exception("WordOp - Invalid operation " + command);
				//******************************************************************************  

				return ""; // everything must be ok

			} // end of try
Exemplo n.º 13
0
        private void Button2_Click(object sender, EventArgs e)
        {
            int            GetTblIndex    = 0;
            OpenFileDialog openFileDialog = new OpenFileDialog();

            openFileDialog.Filter = ".docx|*.docx";
            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                //File.SetAttributes(openFileDialog.FileName, FileAttributes.);
                direct      = openFileDialog.FileName;
                label4.Text = direct.Split('\\').Last();
            }
            Object missing     = System.Reflection.Missing.Value;
            Object confConv    = false;
            Object readOnly    = false;
            Object isVisible   = false;
            Object saveChanges = false;
            Object filename    = direct;

            _Word.Application word = new _Word.Application();
            _Word.Document    doc  = new _Word.Document();
            doc          = word.Documents.Open(ref filename, ref confConv, ref readOnly);
            word.Visible = false;
            _Word.Tables tbl = doc.Tables;
            for (int i = 1; i < tbl.Count + 1; i++)
            {
                _Word.Range range = tbl[i].Cell(1, 2).Range;
                if (range.Text.Substring(0, 27) == "Наименование разделов и тем")
                {
                    //MessageBox.Show("ALL RIGHT");
                    GetTblIndex = i;
                    break;
                }
            }
            int idList = 0;

            object begCell1 = tbl[GetTblIndex].Cell(1, 4).Range.Start;
            object endCell1 = tbl[GetTblIndex].Cell(2, 5).Range.End;

            _Word.Range ranga = doc.Range(ref begCell1, ref endCell1);
            ranga.Select();
            word.Selection.Cells.Merge();
            //word.Visible = true;
            begCell1 = tbl[GetTblIndex].Cell(2, 2).Range.Start;
            //MessageBox.Show(tbl[GetTblIndex].Cell(2, 2).Range.Text);
            int RowsCount = 0;

            foreach (_Word.Row r in tbl[GetTblIndex].Rows)
            {
                if (r.Cells[2].Range.Text.Substring(0, 4) != "Тема" && RowsCount > 0)
                {
                    break;
                }
                RowsCount++;
            }
            endCell1 = tbl[GetTblIndex].Cell(RowsCount, 6).Range.End;
            //MessageBox.Show(tbl[GetTblIndex].Cell(5, 6).Range.Text);
            _Word.Range CutTbl = doc.Range(ref begCell1, ref endCell1);
            foreach (_Word.Row row in CutTbl.Rows)
            {
                if (row.Cells[2].Range.Text.Substring(0, 4) == "Тема")
                {
                    AllListLec.Add(row.Cells[4].Range.Text.Replace("\a", "").Replace("\r", "") + ";" + row.Cells[2].Range.Text.Replace("\a", "").Replace("\r", ""));
                    AllListPr.Add(row.Cells[5].Range.Text.Replace("\a", "").Replace("\r", "") + ";" + row.Cells[2].Range.Text.Replace("\a", "").Replace("\r", ""));
                    NameOfTheme.Add(row.Cells[2].Range.Text.Replace("\a", "").Replace("\r", ""));
                }
                idList++;
            }
            doc.Close(ref saveChanges);
            word.Quit(ref saveChanges);
        }
Exemplo n.º 14
0
    protected void Button1_Click(object sender, EventArgs e)
    {
        StudentsRotaryBLL studentsRotaryBLL = new StudentsRotaryBLL();

        dt = new DataTable();

        try
        {
            string templatePath = HttpContext.Current.Server.MapPath(@"../RotaryTemplete/RotaryTemplete.docx");
            //生成的文档路径
            filePath = HttpContext.Current.Server.MapPath(@"../RotaryWord/");
            if (!Directory.Exists(filePath))
            {
                Directory.CreateDirectory(filePath);
            }
            if (!File.Exists(templatePath))
            {
                Response.Write("<script>alert('error:服务器没有模版');</script>"); return;
            }
            ;
            DataTable dt_Stu = studentsRotaryBLL.GetDtByNT(name, tbCode);

            filePath = filePath + "个人轮转表-" + dt_Stu.Rows[0]["real_name"] + ".doc";
            //copy一份
            File.Copy(templatePath, filePath, true);

            object oMissing = System.Reflection.Missing.Value;
            app         = new Word.Application();
            app.Visible = false;
            object fileName = filePath;
            doc = app.Documents.Open(ref fileName,
                                     ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
                                     ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
                                     ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing);

            if (doc == null)
            {
                Response.Write("<script>alert('error:服务器没有打开Word');</script>");
                return;
            }

            ////判断书签 //加入doc书签的方法
            //if (doc.Bookmarks.Exists("KJJBJNF"))
            //{
            //    doc.Bookmarks["KJJBJNF"].Range.Text = DateTime.Now.ToString("yyyyMMddHHmmss").ToString() + "标题";
            //}


            Word.Tables tabs1 = doc.Tables;
            if (tabs1 != null && tabs1.Count > 0)
            {
                Word.Table dt_Word = tabs1[1];


                doc.Bookmarks["TrainingBaseName"].Range.Text = dt_Stu.Rows[0]["training_base_name"].ToString();
                //默认从第2行开始,第1行为模板中的标头
                int rowIdex = 2;
                foreach (DataRow row in dt_Stu.Rows)
                {
                    object miss = System.Reflection.Missing.Value;
                    dt_Word.Rows.Add(miss);

                    //将从数据库中查询的数据,此处进行循环加载即可


                    //1. 设置该单元格中字体的对齐方式
                    dt_Word.Cell(rowIdex, 1).Range.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter;
                    //2.向单元格中添加数据
                    dt_Word.Cell(rowIdex, 1).Range.Text = row["real_name"].ToString();
                    dt_Word.Cell(rowIdex, 2).Range.Text = row["professional_base_name"].ToString();
                    dt_Word.Cell(rowIdex, 3).Range.Text = row["rotary_dept_name"].ToString();
                    dt_Word.Cell(rowIdex, 4).Range.Text = row["rotary_begin_time"].ToString();
                    dt_Word.Cell(rowIdex, 5).Range.Text = row["rotary_end_time"].ToString();
                    dt_Word.Cell(rowIdex, 6).Range.Text = row["instructor"].ToString();
                    // 3 .合并单元格Merge(行,列)
                    //dt_Word.Cell(rowIdex, 3).Merge(dt_Word.Cell(rowIdex, 4));

                    rowIdex++;
                }
            }
            doc.Save();
            QuitWord();
        }
        catch (Exception ex)
        {
            QuitWord();
            Response.Write("<script>alert('" + ex.Message + "');</script>");
        }



        //Word._Application appWord = new Word.ApplicationClass();
        //Word._Document docFile = null;
        //try
        //{
        //    appWord.Visible = false;
        //    object objTrue = true;
        //    object objFalse = false;
        //    object objTemplate = Server.MapPath(@"../RotaryTemplete/RotaryTemplete.docx");//模板路径
        //    object objDocType = Word.WdDocumentType.wdTypeDocument;
        //    docFile = appWord.Documents.Add(ref objTemplate, ref objFalse, ref objDocType, ref objTrue);
        //    //第一步生成word文档
        //    //定义书签变量
        //    object TrainingBaseName = "TrainingBaseName";
        //    object StudentsRealName = "StudentsRealName";
        //    object ProfessionalBaseName = "ProfessionalBaseName";
        //    object DeptName = "DeptName";
        //    object RotaryBeginTime = "RotaryBeginTime";
        //    object RotaryEndTime = "RotaryEndTime";
        //    object TeachersRealName = "TeachersRealName";

        //    //第二步 读取数据,填充数据集
        //    //SqlDataReader dr = XXXXX;//读取出来的数据集
        //    //第三步 给书签赋值
        //    //给书签赋值
        //     dt = studentsRotaryBLL.GetDtByNT(name, tbCode);
        //     if (dt == null)
        //     {
        //         Response.Write("<script>alert('暂无轮转信息');</script>");
        //         return;
        //     }
        //     else
        //     {
        //         foreach (DataRow row in dt.Rows)
        //         {
        //             docFile.Bookmarks.get_Item(ref TrainingBaseName).Range.Text = row["training_base_name"].ToString();
        //             docFile.Bookmarks.get_Item(ref StudentsRealName).Range.Text = row["real_name"].ToString();
        //             docFile.Bookmarks.get_Item(ref ProfessionalBaseName).Range.Text = row["professional_base_name"].ToString();
        //             docFile.Bookmarks.get_Item(ref DeptName).Range.Text = row["rotary_dept_name"].ToString();
        //             docFile.Bookmarks.get_Item(ref RotaryBeginTime).Range.Text = row["rotary_begin_time"].ToString();
        //             docFile.Bookmarks.get_Item(ref RotaryEndTime).Range.Text = row["rotary_end_time"].ToString();
        //             docFile.Bookmarks.get_Item(ref TeachersRealName).Range.Text = row["instructor"].ToString();
        //         }
        //     }


        //    //第四步 生成word
        //    object filename = Server.MapPath("../RotaryWord/") + "个人轮转表-"+dt.Rows[0]["real_name"]+".doc";
        //    object miss = System.Reflection.Missing.Value;
        //    docFile.SaveAs(ref filename, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss);
        //    object missingValue = Type.Missing;
        //    object doNotSaveChanges = Word.WdSaveOptions.wdDoNotSaveChanges;
        //    docFile.Close(ref doNotSaveChanges, ref missingValue, ref missingValue);
        //    appWord.Quit(ref miss, ref miss, ref miss);
        //    docFile = null;
        //    appWord = null;
        //}
        //catch (Exception ex)
        //{
        //    //捕捉异常,如果出现异常则清空实例,退出word,同时释放资源
        //    string aa = e.ToString();
        //    object miss = System.Reflection.Missing.Value;
        //    object missingValue = Type.Missing;
        //    object doNotSaveChanges = Word.WdSaveOptions.wdDoNotSaveChanges;
        //    docFile.Close(ref doNotSaveChanges, ref missingValue, ref missingValue);
        //    appWord.Quit(ref miss, ref miss, ref miss);
        //    docFile = null;
        //    appWord = null;
        //    throw ex;
        //}
    }
Exemplo n.º 15
0
 public TableBuilder(Microsoft.Office.Interop.Word.Tables tables)
 {
     Tables     = tables;
     _retrieved = new bool[tables.Count];
 }
 public ParseWorkPrograming(string inputFilePath, List <Discipline> disciplenes)
 {
     this.doc         = FilesAPI.WordAPI.GetDocument(inputFilePath);
     this.table       = doc.Tables;
     this.disciplenes = disciplenes;
 }