本文整理汇总了C#中Microsoft.Office.Interop.Excel.ApplicationClass.Run方法的典型用法代码示例。如果您正苦于以下问题:C# ApplicationClass.Run方法的具体用法?C# ApplicationClass.Run怎么用?C# ApplicationClass.Run使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.Office.Interop.Excel.ApplicationClass
的用法示例。
在下文中一共展示了ApplicationClass.Run方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DoExport
public ExportResult DoExport(string fileName, int userId, ExportType exportType)
{
try
{
System.Globalization.CultureInfo oldCI = System.Threading.Thread.CurrentThread.CurrentCulture;
System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US");
excel.Application xlsApp = new excel.ApplicationClass();
xlsApp.DisplayAlerts = false;
excel.Workbook xlsWorkbook;
excel.Worksheet xlsWorksheet;
excel.Range rng = null;
object missing = System.Reflection.Missing.Value;
xlsWorkbook = xlsApp.Workbooks.Open(Path.Combine(Environment.CurrentDirectory, @"Exports\WHO_EPIRF_PC_NATDAT.xls"),
missing, missing, missing, missing, missing, missing, missing,
missing, missing, missing, missing, missing, missing, missing);
Country country = demo.GetCountry();
int reportYear = DateTime.Now.Year;
xlsWorksheet = (excel.Worksheet)xlsWorkbook.Worksheets[1];
AddInfo(xlsWorksheet, rng, country, exportType, ref reportYear);
//xlsApp.Visible = true; //set to 'true' when debbugging, Exec is visible
//xlsApp.DisplayAlerts = true; //enable all the prompt alerts for debug.
DateTime start = new DateTime(reportYear, 1, 1);
DateTime end = new DateTime(reportYear, 12, 31);
xlsWorksheet = (excel.Worksheet)xlsWorkbook.Worksheets[2];
AddLfMm(xlsWorksheet, start, end);
xlsApp.Run("Sheet13.UNIT_LF");
xlsWorksheet = (excel.Worksheet)xlsWorkbook.Worksheets[3];
AddOncho(xlsWorksheet, start, end);
xlsApp.Run("Sheet17.UNIT_ONCHO");
xlsWorksheet = (excel.Worksheet)xlsWorkbook.Worksheets[4];
AddSth(xlsWorksheet, start, end);
xlsApp.Run("Sheet15.UNIT_STH");
xlsWorksheet = (excel.Worksheet)xlsWorkbook.Worksheets[5];
AddSch(xlsWorksheet, start, end);
xlsApp.Run("Sheet16.UNIT_SCH");
xlsWorkbook.SaveAs(fileName, excel.XlFileFormat.xlOpenXMLWorkbook, missing,
missing, false, false, excel.XlSaveAsAccessMode.xlNoChange,
excel.XlSaveConflictResolution.xlUserResolution, true,
missing, missing, missing);
xlsApp.ScreenUpdating = true;
xlsApp.Visible = true;
rng = null;
Marshal.ReleaseComObject(xlsWorksheet);
Marshal.ReleaseComObject(xlsWorkbook);
Marshal.ReleaseComObject(xlsApp);
System.Threading.Thread.CurrentThread.CurrentCulture = oldCI;
return new ExportResult { WasSuccess = true };
}
catch (Exception ex)
{
return new ExportResult(ex.Message);
}
}
示例2: ExportData
public ExportResult ExportData(string filePath, int userId, ExportJrfQuestions questions)
{
try
{
int yearReported = questions.JrfYearReporting.Value;
System.Globalization.CultureInfo oldCI = System.Threading.Thread.CurrentThread.CurrentCulture;
System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US");
excel.Application xlsApp = new excel.ApplicationClass();
excel.Workbook xlsWorkbook;
excel.Worksheet xlsWorksheet;
excel.Worksheet xlsSummary;
excel.Range rng = null;
object missing = System.Reflection.Missing.Value;
// Open workbook
xlsWorkbook = xlsApp.Workbooks.Open(Path.Combine(Environment.CurrentDirectory, @"Exports\WHO_JRF_PC.xls"),
missing, missing, missing, missing, missing, missing, missing,
missing, missing, missing, missing, missing, missing, missing);
var districtLevel = questions.AdminLevelType;
CountryDemography countryStats = demo.GetCountryLevelStatsRecent();
Country country = demo.GetCountry();
List<AdminLevel> demography = new List<AdminLevel>();
DateTime startDate = new DateTime(yearReported, 1, 1);
DateTime endDate = startDate.AddYears(1).AddDays(-1);
List<AdminLevel> tree = demo.GetAdminLevelTreeForDemography(districtLevel.LevelNumber, startDate, endDate, ref demography);
var reportingLevelUnits = demography.Where(d => d.LevelNumber == districtLevel.LevelNumber).ToList();
Dictionary<int, DataRow> aggIntvs = GetIntvsAggregatedToReportingLevel(startDate, endDate, reportingLevelUnits);
// Info page
xlsWorksheet = (excel.Worksheet)xlsWorkbook.Worksheets[1];
xlsWorksheet.Unprotect();
AddQuestions(xlsWorksheet, rng, questions, countryStats, demography, districtLevel.LevelNumber, country);
// run macro to create district rows.
xlsApp.DisplayAlerts = false;
xlsApp.Run("Sheet1.DISTRICT");
xlsWorksheet = (excel.Worksheet)xlsWorkbook.Worksheets[2];
xlsWorksheet.Unprotect();
AddDemo(xlsWorksheet, rng, demography, districtLevel.LevelNumber, startDate, endDate);
// Summary
xlsSummary = (excel.Worksheet)xlsWorkbook.Sheets["SUMMARY"];
// ALL THE INTVS
AddT3(xlsWorkbook, xlsWorksheet, xlsSummary, rng, reportingLevelUnits, aggIntvs);
AddT2(xlsWorkbook, xlsWorksheet, xlsSummary, rng, reportingLevelUnits, aggIntvs);
AddT1(xlsWorkbook, xlsWorksheet, xlsSummary, rng, reportingLevelUnits, aggIntvs);
AddMDA4(xlsWorkbook, xlsWorksheet, xlsSummary, rng, reportingLevelUnits, aggIntvs);
AddMDA3(xlsWorkbook, xlsWorksheet, xlsSummary, rng, reportingLevelUnits, aggIntvs);
AddMDA2(xlsWorkbook, xlsWorksheet, xlsSummary, rng, reportingLevelUnits, aggIntvs);
AddMDA1(xlsWorkbook, xlsWorksheet, xlsSummary, rng, reportingLevelUnits, aggIntvs);
AddDistricts(xlsWorkbook, xlsWorksheet, xlsSummary, rng, reportingLevelUnits, aggIntvs);
xlsWorkbook.SaveAs(filePath, excel.XlFileFormat.xlOpenXMLWorkbook, missing,
missing, false, false, excel.XlSaveAsAccessMode.xlNoChange,
excel.XlSaveConflictResolution.xlUserResolution, true,
missing, missing, missing);
xlsApp.ScreenUpdating = true;
xlsApp.Visible = true;
rng = null;
Marshal.ReleaseComObject(xlsWorksheet);
Marshal.ReleaseComObject(xlsWorkbook);
Marshal.ReleaseComObject(xlsApp);
System.Threading.Thread.CurrentThread.CurrentCulture = oldCI;
return new ExportResult { WasSuccess = true };
}
catch (Exception ex)
{
return new ExportResult(ex.Message);
}
}