You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
161 lines
4.6 KiB
161 lines
4.6 KiB
using Microsoft.Office.Interop.Excel;
|
|
using Microsoft.Office.Interop.Word;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data;
|
|
using System.Linq;
|
|
using System.Linq.Expressions;
|
|
using System.Runtime.InteropServices;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace OnDocOffice
|
|
{
|
|
public class clsExcelEdit
|
|
{
|
|
public string connectstring { get; set; }
|
|
public string filename { get; set; }
|
|
public string dokumentid { get; set; }
|
|
public
|
|
Microsoft.Office.Interop.Excel.Application excel;
|
|
Workbook workBook = null;
|
|
|
|
|
|
public clsExcelEdit(string connectstring, string filename, string dokumentid)
|
|
{
|
|
this.connectstring = connectstring;
|
|
this.filename = filename;
|
|
this.dokumentid = dokumentid;
|
|
|
|
}
|
|
|
|
public bool Start_Application()
|
|
{
|
|
try
|
|
{
|
|
excel = new Microsoft.Office.Interop.Excel.Application();
|
|
return true;
|
|
}
|
|
catch
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
|
|
public void Edit_Document()
|
|
{
|
|
Start_Application();
|
|
workBook = excel.Workbooks.Open(filename);
|
|
excel.Visible = true;
|
|
//clsProcessWatch.AddToList(dokumentid, filename, "Word");
|
|
bool isClosed = IsDocumentClosed(excel, workBook);
|
|
workBook = null;
|
|
excel = null;
|
|
}
|
|
|
|
public void Control_Word(string dokumentid, string filename, string application)
|
|
{
|
|
//clsProcessWatch.AddToList(dokumentid, filename, application);
|
|
}
|
|
|
|
static bool IsDocumentClosed(Microsoft.Office.Interop.Excel.Application excelApp, Workbook workBook)
|
|
{
|
|
// Check if the document is still listed in the Documents collection
|
|
foreach (Workbook openDoc in excelApp.Workbooks)
|
|
{
|
|
if (openDoc.FullName == workBook.FullName)
|
|
{
|
|
return false; // Document is still open
|
|
}
|
|
}
|
|
return true; // Document is closed
|
|
}
|
|
|
|
public void run_macros()
|
|
{
|
|
|
|
}
|
|
}
|
|
|
|
public class clsWordEdit
|
|
{
|
|
public string connectstring { get; set; }
|
|
public string filename { get; set; }
|
|
public string dokumentid { get; set; }
|
|
public
|
|
Microsoft.Office.Interop.Word.Application word;
|
|
Document doc = null;
|
|
|
|
|
|
public clsWordEdit(string connectstring, string filename, string dokumentid)
|
|
{
|
|
this.connectstring = connectstring;
|
|
this.filename = filename;
|
|
this.dokumentid = dokumentid;
|
|
|
|
}
|
|
|
|
public bool Start_Application()
|
|
{
|
|
try
|
|
{
|
|
word = new Microsoft.Office.Interop.Word.Application();
|
|
word.Run("Autoexec");
|
|
return true;
|
|
}
|
|
catch
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
|
|
public void Edit_Document(bool runmacros)
|
|
{
|
|
Start_Application();
|
|
doc = word.Documents.Open(filename);
|
|
word.Visible = true;
|
|
|
|
if (runmacros == true)
|
|
{
|
|
Database.DB db = new Database.DB(connectstring);
|
|
db.Get_Tabledata("Select * from ondoc_macros where dokumentid='" + dokumentid + "' order by reihenfolge", false, true);
|
|
foreach (DataRow dr in db.dsdaten.Tables[0].Rows)
|
|
{
|
|
try
|
|
{
|
|
word.Run(dr[0].ToString());
|
|
}
|
|
catch ( Exception e) { string a = e.Message;}
|
|
}
|
|
}
|
|
//clsProcessWatch.AddToList(dokumentid, filename, "Word");
|
|
bool isClosed = IsDocumentClosed(word, doc);
|
|
doc = null;
|
|
word = null;
|
|
}
|
|
|
|
public void Control_Word(string dokumentid, string filename, string application)
|
|
{
|
|
//clsProcessWatch.AddToList(dokumentid, filename, application);
|
|
}
|
|
|
|
static bool IsDocumentClosed(Microsoft.Office.Interop.Word.Application wordApp, Document doc)
|
|
{
|
|
// Check if the document is still listed in the Documents collection
|
|
foreach (Document openDoc in wordApp.Documents)
|
|
{
|
|
if (openDoc.FullName == doc.FullName)
|
|
{
|
|
return false; // Document is still open
|
|
}
|
|
}
|
|
return true; // Document is closed
|
|
}
|
|
|
|
public void run_macros()
|
|
{
|
|
|
|
}
|
|
}
|
|
}
|