本文整理汇总了C#中ApplicationClass类的典型用法代码示例。如果您正苦于以下问题:C# ApplicationClass类的具体用法?C# ApplicationClass怎么用?C# ApplicationClass使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ApplicationClass类属于命名空间,在下文中一共展示了ApplicationClass类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ExportToExcel
public void ExportToExcel(DataGridView grid,string r_id,string time)
{
ApplicationClass Excel = new ApplicationClass();
XlReferenceStyle RefStyle = Excel.ReferenceStyle;
Excel.Visible = true;
Workbook wb = null;
String TemplatePath = System.Windows.Forms.Application.StartupPath + @"\Отчет"+r_id+".xlt";
try
{
wb = Excel.Workbooks.Add(TemplatePath); // !!!
}
catch (System.Exception ex)
{
throw new Exception("Не удалось загрузить шаблон для экспорта " + TemplatePath + "\n" + ex.Message);
}
Worksheet ws = wb.Worksheets.get_Item(1) as Worksheet;
ws.Cells[20, 3] = time;
for (int j = 0; j < grid.Columns.Count; ++j)
{
//(ws.Cells[1+20, j + 1+2] as Range).Value2 = grid.Columns[j].HeaderText;
for (int i = 0; i < grid.Rows.Count; ++i)
{
object Val = grid.Rows[i].Cells[j].Value;
if (Val != null)
(ws.Cells[i + 2+20, j + 1+2] as Range).Value2 = Val.ToString();
}
}
// ws.Columns.EntireColumn.AutoFit();
Excel.ReferenceStyle = RefStyle;
ReleaseExcel(Excel as Object);
}
示例2: ConvertDocument
void ConvertDocument(Guid g, string fileName)
{
object m = System.Reflection.Missing.Value;
object oldFileName = (object)fileName;
object readOnly = (object)false;
ApplicationClass ac = null;
System.Globalization.CultureInfo oldCI = System.Threading.Thread.CurrentThread.CurrentCulture;
try
{
System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US");
// First, create a new Microsoft.Office.Interop.Word.ApplicationClass.
ac = new ApplicationClass();
// Now we open the document.
Presentation doc = ac.Presentations.Open(fileName , Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoFalse);
// Create a temp file to save the HTML file to.
string tempFileName = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.InternetCache), g.ToString() + ".html");
// Cast these items to object. The methods we're calling
// only take object types in their method parameters.
// Save the file.
doc.SaveAs(tempFileName, Microsoft.Office.Interop.PowerPoint.PpSaveAsFileType.ppSaveAsHTML, Microsoft.Office.Core.MsoTriState.msoFalse);
}
finally
{
// Make sure we close the application class.
if (ac != null)
ac.Quit();
System.Threading.Thread.CurrentThread.CurrentCulture = oldCI;
}
}
示例3: SaveExcelFile
public static void SaveExcelFile(string fileName, string tempFileName,string[,] contents, int startColumn, int startRow)
{
try
{
excelApp = new ApplicationClass();
Workbooks myWorkBooks = excelApp.Workbooks;
myWorkBooks.Open(tempFileName, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing);
Sheets sheets = excelApp.Sheets;
mySheet1 = (Worksheet)sheets[1];
mySheet1.Activate();
//写入测试信息
Range range1 = mySheet1.get_Range(mySheet1.Cells[startRow, startColumn], mySheet1.Cells[contents.GetLength(0)+startRow-1,contents.GetLength(1)+startColumn-1]);
range1.Value2 = contents;
mySheet1.SaveAs(fileName, missing, missing, missing, missing, missing, missing, missing, missing, missing);
myWorkBooks.Close();
excelApp.Quit();
excelApp = null;
}
catch (Exception ee)
{
throw ee;
}
}
示例4: getTestSpecificationDocTOC
public Dictionary<string, List<TermContainer>> getTestSpecificationDocTOC(Document doc, ApplicationClass app)
{
generateTOC(doc, app);
Range tocRange = doc.TablesOfContents[1].Range;
string[] tocContents = delimiterTOC(tocRange.Text);
Dictionary<string, List<TermContainer>> dict = new Dictionary<string, List<TermContainer>>();
string chapter = "";
foreach (string s in tocContents)
{
if (isLevel1(s))
{
chapter = s;
dict.Add(s, new List<TermContainer>());
}
else
{
if (isLevel2(s))
{
TermContainer term = new TermContainer("", s, null);
dict[chapter].Add(term);
}
}
}
return dict;
}
示例5: EncryptExcelByPassword
/// <summary>
///
/// </summary>
/// <param name="UnEncryptFileName">Excel原始檔名</param>
/// <param name="EncryptFileName">Excel加密後檔名</param>
/// <param name="OpenExcelPassword">允許開啟密碼</param>
/// <param name="WriteExcelPassword">允許編寫密碼</param>
public static void EncryptExcelByPassword(string UnEncryptFileName, string EncryptFileName,
string OpenExcelPassword, string WriteExcelPassword)
{
ApplicationClass xApp = new ApplicationClass();
try
{
Workbook xBook = xApp.Workbooks.Open(UnEncryptFileName,
Missing.Value, Missing.Value, Missing.Value, Missing.Value,
Missing.Value, Missing.Value, Missing.Value, Missing.Value,
Missing.Value, Missing.Value, Missing.Value, Missing.Value);
if (File.Exists(EncryptFileName)) File.Delete(EncryptFileName);
xBook.SaveAs(EncryptFileName, XlFileFormat.xlExcel12
, OpenExcelPassword, WriteExcelPassword, Missing.Value,
Missing.Value, XlSaveAsAccessMode.xlNoChange, Missing.Value,
Missing.Value, Missing.Value, Missing.Value, Missing.Value);
xBook.Save();
xBook.Close();
xBook = null;
}
catch (Exception ex)
{
throw ex;
}
finally
{
xApp.Quit();
System.Runtime.InteropServices.Marshal.ReleaseComObject(xApp);
xApp = null;
}
GC.Collect();
}
示例6: x
private void x()
{
Excel.Application app = new ApplicationClass();
try
{
//app.ActivePrinter = "Acrobat Distiller";
Workbooks workBooks = app.Workbooks;
Workbook workBook = (Workbook )workBooks.GetType().InvokeMember("Open",BindingFlags.InvokeMethod,null,workBooks,new object[]{@"C:\Documents and Settings\raghunandanr\Desktop\Template Format for PDF Transcription1.xls"});
workBook.PrintOut(1,Type.Missing,1,false,"Acrobat Distiller",true,true,@"C:\Documents and Settings\raghunandanr\Desktop\Template Format for PDF Transcription1.ps");
workBook.Close(false,Type.Missing,Type.Missing);
PdfDistiller dist = new PdfDistillerClass();
//dist.bSpoolJobs = 1;
dist.bShowWindow = 0;
dist.OnJobFail += new _PdfEvents_OnJobFailEventHandler(Fail);
dist.FileToPDF(@"C:\Documents and Settings\raghunandanr\Desktop\Template Format for PDF Transcription1.ps",null,null);
Marshal.ReleaseComObject(dist);
dist=null;
}
catch(Exception ex){Response.Write(ex.Message);}
finally
{
app.Quit();
Marshal.ReleaseComObject(app);
app = null;
GC.Collect();
GC.WaitForPendingFinalizers();
}
}
示例7: GetSheetNames
public static List<string> GetSheetNames(string fileName)
{
ApplicationClass excelapp = new ApplicationClass();
RecentFile re = excelapp.RecentFiles.Add(fileName);// nhan ve file vua chon de xu ly
List<string> lstSheet = new List<string>();
try
{
excelapp.Visible = false;
Workbook excelWorkbook = re.Open();// mở ra và có thể truy xuất các sheet
if (excelWorkbook.Sheets.Count > 0)
{
Worksheet excelWorkSheet;
for (int i = 1; i <= excelWorkbook.Sheets.Count; i++)
{
excelWorkSheet = (Worksheet)excelWorkbook.Sheets[i];
lstSheet.Add(excelWorkSheet.Name);
}
excelWorkSheet = null;
}
excelWorkbook = null;
re.Application.Quit();
excelapp.Quit();// thoat khoi chuong trinh excel.exe trong he thong
}
catch (Exception) { }
return lstSheet;
}
示例8: DataTableToWorkBook
public static Workbook DataTableToWorkBook(System.Data.DataTable dt, string[] Cells)
{
if (dt.Columns.Count < 1)
{
throw new Exception("_Excel.DataTableToWorkBook 方法提供的 DataTable 参数找不到任何可用的列。");
}
Application application = new ApplicationClass();
Workbook workbook = application.Workbooks.Add(XlWBATemplate.xlWBATWorksheet);
Worksheet worksheet = (Worksheet) workbook.Worksheets[1];
long count = dt.Rows.Count;
long num2 = 0L;
for (int i = 0; i < dt.Columns.Count; i++)
{
if (((Cells != null) && (Cells.Length > i)) && !string.IsNullOrEmpty(Cells[i]))
{
worksheet.Cells[1, i + 1] = Cells[i].Trim();
}
else
{
worksheet.Cells[1, i + 1] = dt.Columns[i].ColumnName;
}
Microsoft.Office.Interop.Excel.Range range1 = (Microsoft.Office.Interop.Excel.Range) worksheet.Cells[1, i + 1];
}
for (int j = 0; j < dt.Rows.Count; j++)
{
for (int k = 0; k < dt.Columns.Count; k++)
{
worksheet.Cells[j + 2, k + 1] = dt.Rows[j][k];
Microsoft.Office.Interop.Excel.Range range2 = (Microsoft.Office.Interop.Excel.Range) worksheet.Cells[j + 2, k + 1];
}
num2 += 1L;
float single1 = ((float) (100L * num2)) / ((float) count);
}
return workbook;
}
示例9: Bai2_Load
private void Bai2_Load(object sender, EventArgs e)
{
Microsoft.Office.Interop.Word.ApplicationClass wordApplication = new ApplicationClass();
object o_nullobject = System.Reflection.Missing.Value;
object o_filePath = System.IO.Directory.GetCurrentDirectory() + "\\Resources\\PhepNhan.doc";
object o_format = Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatHTML;
object o_encoding = Microsoft.Office.Core.MsoEncoding.msoEncodingUTF8;
object o_endings = Microsoft.Office.Interop.Word.WdLineEndingType.wdCRLF;
object o_Readonly = true;
Microsoft.Office.Interop.Word.Document doc = wordApplication.Documents.Open(ref o_filePath,
ref o_nullobject, ref o_Readonly, ref o_nullobject, ref o_nullobject, ref o_nullobject,
ref o_nullobject, ref o_nullobject, ref o_nullobject, ref o_nullobject, ref o_nullobject, ref o_nullobject, ref o_nullobject, ref o_nullobject,
ref o_nullobject, ref o_nullobject);
doc.ActiveWindow.Selection.WholeStory();
doc.ActiveWindow.Selection.Copy();
IDataObject data = Clipboard.GetDataObject();
txtLyThuyet.Text = data.GetData(DataFormats.UnicodeText).ToString();
doc.Close(ref o_nullobject, ref o_nullobject, ref o_nullobject);
wordApplication.Quit(ref o_nullobject, ref o_nullobject, ref o_nullobject);
PhepTinhDAO phepTinhDAO = new PhepTinhDAO();
PhepTinhDTO phepTinhDTO = new PhepTinhDTO();
arrPhepTinh = phepTinhDAO.getPhepTinhNhan();
sizeOfXML = arrPhepTinh.Count;
phepTinhDTO = (PhepTinhDTO)arrPhepTinh[0];
tbTemp1.Text = phepTinhDTO.SoThuNhat.ToString();
tbTemp2.Text = phepTinhDTO.SoThuHai.ToString();
}
示例10: InstrumentationCanBeAttachedToInstrumentationProviderWhenInstanceNameIsPresent
public void InstrumentationCanBeAttachedToInstrumentationProviderWhenInstanceNameIsPresent()
{
ApplicationClass applicationObject = new ApplicationClass();
strategy.AttachInstrumentation("InstanceName", applicationObject, instrumentationConfigurationSource, reflectionCache);
Assert.IsTrue(((InstrumentationProvider) (applicationObject.GetInstrumentationEventProvider())).IsWired);
}
示例11: ConvertDocument
void ConvertDocument(Guid g, string fileName)
{
object m = System.Reflection.Missing.Value;
object oldFileName = (object)fileName;
object readOnly = (object)false;
ApplicationClass ac = null;
try
{
// First, create a new Microsoft.Office.Interop.Word.ApplicationClass.
ac = new ApplicationClass();
// Now we open the document.
Document doc = ac.Documents.Open(ref oldFileName, ref m, ref readOnly,
ref m, ref m, ref m, ref m, ref m, ref m, ref m,
ref m, ref m, ref m, ref m, ref m, ref m);
// Create a temp file to save the HTML file to.
string tempFileName =Environment.GetFolderPath(Environment.SpecialFolder.InternetCache) + g.ToString() + ".html";
// Cast these items to object. The methods we're calling
// only take object types in their method parameters.
object newFileName = (object)tempFileName;
// We will be saving this file as HTML format.
object fileType = (object)WdSaveFormat.wdFormatHTML;
// Save the file.
doc.SaveAs(ref newFileName, ref fileType,
ref m, ref m, ref m, ref m, ref m, ref m, ref m,
ref m, ref m, ref m, ref m, ref m, ref m, ref m);
}
finally
{
// Make sure we close the application class.
if (ac != null)
ac.Quit(ref readOnly, ref m, ref m);
}
}
示例12: Read
private static Worksheet mySheet1; //工作簿1
#endregion Fields
#region Methods
public static List<List<string>> Read(string fileName,int columnCount,int startRowIndex)
{
List<List<string>> textList = new List<List<string>>();
excelApp = new ApplicationClass();
Workbooks myWorkBooks = excelApp.Workbooks;
myWorkBooks.Open(fileName, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing);
Sheets sheets = excelApp.Sheets;
mySheet1 = (Worksheet)sheets[1];
int rowCount = mySheet1.UsedRange.Rows.Count;
if (rowCount != 0)
{
for (int i = startRowIndex; i <= rowCount; i++)
{
string name = ((Range)mySheet1.Cells[i, 2]).Text.ToString();
if (name != "") {
List<string> list = new List<string>();
list.Add((i-startRowIndex+1).ToString());
for (int j = 0; j < columnCount; j++)
{
list.Add(((Range)mySheet1.Cells[i, j + 1]).Text.ToString());
}
textList.Add(list);
}
}
}
myWorkBooks.Close();
excelApp.Quit();
excelApp = null;
return textList;
}
示例13: WriteToNewWordFile
public static void WriteToNewWordFile(string path, string text)
{
ApplicationClass wordApp = new ApplicationClass();
object nullobj = Missing.Value;
object file = path;
object fileFormat = WdSaveFormat.wdFormatHTML;
object encoding = Microsoft.Office.Core.MsoEncoding.msoEncodingUTF8;
FileUtils.WriteAllText(path, text);
var doc = wordApp.Documents.Add(ref nullobj, ref nullobj, ref nullobj, ref nullobj);
if (text.IsNull())// If file open in first time save as word html
{
doc.SaveAs(ref file, ref fileFormat, ref nullobj, ref nullobj,
ref nullobj, ref nullobj, ref nullobj, ref nullobj,
ref nullobj, ref nullobj, ref nullobj,
/*Encoding*/ref encoding, ref nullobj, ref nullobj, ref nullobj, ref nullobj);
}
(doc as _Document).Close(ref nullobj, ref nullobj, ref nullobj);
wordApp.Quit(ref nullobj, ref nullobj, ref nullobj);
}
示例14: Word2Pdf
public static void Word2Pdf(string path, string savepath)
{
var word = new ApplicationClass();
var wordType = word.GetType();
var docs = word.Documents;
var docsType = docs.GetType();
var doc = (Document) docsType.InvokeMember(
"Open",
BindingFlags.InvokeMethod,
null,
docs,
new[] {(object)path, true, true});
var docType = doc.GetType();
docType.InvokeMember(
"SaveAs",
BindingFlags.InvokeMethod,
null,
doc,
new[] {(object) savepath, WdSaveFormat.wdFormatPDF});
docType.InvokeMember(
"Close",
BindingFlags.InvokeMethod,
null,
doc,
new object[] {WdSaveOptions.wdDoNotSaveChanges});
wordType.InvokeMember(
"Quit",
BindingFlags.InvokeMethod,
null,
word,
null);
}
示例15: Bai1_Load
private void Bai1_Load(object sender, EventArgs e)
{
currentIndex=0;
So5ChuSoDAO so5ChuSoDAO = new So5ChuSoDAO();
So5ChuSoDTO so5ChuSoDTO = null;
arrSo5ChuSo = so5ChuSoDAO.getSo5ChuSo();
sizeOfXML = arrSo5ChuSo.Count;
so5ChuSoDTO = (So5ChuSoDTO)arrSo5ChuSo[0];
lbDocSo.Text = so5ChuSoDTO.Text;
currentResult = so5ChuSoDTO.Number;
Microsoft.Office.Interop.Word.ApplicationClass wordApplication = new ApplicationClass();
object o_nullobject = System.Reflection.Missing.Value;
object o_filePath = System.IO.Directory.GetCurrentDirectory() + "\\Resources\\CacSoCo5ChuSo.doc";
object o_format = Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatHTML;
object o_encoding = Microsoft.Office.Core.MsoEncoding.msoEncodingUTF8;
object o_endings = Microsoft.Office.Interop.Word.WdLineEndingType.wdCRLF;
object o_Readonly = true;
Microsoft.Office.Interop.Word.Document doc = wordApplication.Documents.Open(ref o_filePath,
ref o_nullobject, ref o_Readonly, ref o_nullobject, ref o_nullobject, ref o_nullobject,
ref o_nullobject, ref o_nullobject, ref o_nullobject, ref o_nullobject, ref o_nullobject, ref o_nullobject, ref o_nullobject, ref o_nullobject,
ref o_nullobject, ref o_nullobject);
doc.ActiveWindow.Selection.WholeStory();
doc.ActiveWindow.Selection.Copy();
IDataObject data = Clipboard.GetDataObject();
txtLyThuyet.Text = data.GetData(DataFormats.UnicodeText).ToString();
doc.Close(ref o_nullobject, ref o_nullobject, ref o_nullobject);
wordApplication.Quit(ref o_nullobject, ref o_nullobject, ref o_nullobject);
}