本文整理汇总了C#中Microsoft.Office.Interop.Excel.Application类的典型用法代码示例。如果您正苦于以下问题:C# Application类的具体用法?C# Application怎么用?C# Application使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Application类属于Microsoft.Office.Interop.Excel命名空间,在下文中一共展示了Application类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: ExpotToExcel
public void ExpotToExcel(DataGridView dataGridView1,string SaveFilePath)
{
xlApp = new Excel.Application();
xlWorkBook = xlApp.Workbooks.Add(misValue);
xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);
int i = 0;
int j = 0;
for (i = 0; i <= dataGridView1.RowCount - 1; i++)
{
for (j = 0; j <= dataGridView1.ColumnCount - 1; j++)
{
DataGridViewCell cell = dataGridView1[j, i];
xlWorkSheet.Cells[i + 1, j + 1] = cell.Value;
}
}
xlWorkBook.SaveAs(SaveFilePath, Excel.XlFileFormat.xlWorkbookNormal, misValue, misValue, misValue, misValue, Excel.XlSaveAsAccessMode.xlExclusive, misValue, misValue, misValue, misValue, misValue);
xlWorkBook.Close(true, misValue, misValue);
xlApp.Quit();
releaseObject(xlWorkSheet);
releaseObject(xlWorkBook);
releaseObject(xlApp);
MessageBox.Show("Your file is saved" + SaveFilePath);
}
开发者ID:MisuBeImp,项目名称:DhakaUniversityCyberCenterUserApps,代码行数:27,代码来源:CardUsageController.cs
示例2: Export
public Export(string embedded)
{
string tmp = String.Empty;
try
{
//получаем шаблон из прикладных ресурсов
Stream template = GetResourceFileStream(embedded);
//создаем временный файл
tmp = System.IO.Path.GetTempFileName().Replace(".tmp", ".xlsx");
//сохраняем шаблон во временный файл
using (var fileStream = File.Create(tmp))
{
template.CopyTo(fileStream);
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
// Создаем приложение и открываем в нём временный файл
objApp = new Excel.Application();
objBook = objApp.Workbooks.Open(tmp);
objBook.Activate();
objSheets = objBook.Worksheets;
objSheet = (Excel._Worksheet)objSheets.get_Item(1);
}
开发者ID:hprog,项目名称:exchange,代码行数:26,代码来源:Export.cs
示例3: ExportData
public ExportData(System.Data.DataTable dt, string location)
{
//instantiate excel objects (application, workbook, worksheets)
excel.Application XlObj = new excel.Application();
XlObj.Visible = false;
excel._Workbook WbObj = (excel.Workbook)(XlObj.Workbooks.Add(""));
excel._Worksheet WsObj = (excel.Worksheet)WbObj.ActiveSheet;
//run through datatable and assign cells to values of datatable
int row = 1; int col = 1;
foreach (DataColumn column in dt.Columns)
{
//adding columns
WsObj.Cells[row, col] = column.ColumnName;
col++;
}
//reset column and row variables
col = 1;
row++;
for (int i = 0; i < dt.Rows.Count; i++)
{
//adding data
foreach (var cell in dt.Rows[i].ItemArray)
{
WsObj.Cells[row, col] = cell;
col++;
}
col = 1;
row++;
}
WbObj.SaveAs(location);
}
开发者ID:MattPaul25,项目名称:WebsiteChecker,代码行数:33,代码来源:ExportData.cs
示例4: ExportToExcel
static void ExportToExcel(List<Car> carsInStock)
{
// Load up Excel, then make a new empty workbook.
Excel.Application excelApp = new Excel.Application();
excelApp.Workbooks.Add();
// This example uses a single workSheet.
Excel._Worksheet workSheet = excelApp.ActiveSheet;
// Establish column headings in cells.
workSheet.Cells[1, "A"] = "Make";
workSheet.Cells[1, "B"] = "Color";
workSheet.Cells[1, "C"] = "Pet Name";
// Now, map all data in List<Car> to the cells of the spread sheet.
int row = 1;
foreach (Car c in carsInStock)
{
row++;
workSheet.Cells[row, "A"] = c.Make;
workSheet.Cells[row, "B"] = c.Color;
workSheet.Cells[row, "C"] = c.PetName;
}
// Give our table data a nice look and feel.
workSheet.Range["A1"].AutoFormat(
Excel.XlRangeAutoFormat.xlRangeAutoFormatClassic2);
// Save the file, quit Excel and display message to user.
workSheet.SaveAs(string.Format(@"{0}\Inventory.xlsx", Environment.CurrentDirectory));
excelApp.Quit();
MessageBox.Show("The Inventory.xslx file has been saved to your app folder", "Export complete!");
}
开发者ID:usedflax,项目名称:flaxbox,代码行数:33,代码来源:MainForm.cs
示例5: GetExcelSheetName
private string GetExcelSheetName(string pPath)
{
//打开一个Excel应用
_excelApp = new Excel.Application();
if (_excelApp == null)
{
throw new Exception("打开Excel应用时发生错误!");
}
_books = _excelApp.Workbooks;
//打开一个现有的工作薄
_book = _books.Add(pPath);
_sheets = _book.Sheets;
//选择第一个Sheet页
_sheet = (Excel._Worksheet)_sheets.get_Item(1);
string sheetName = _sheet.Name;
ReleaseCOM(_sheet);
ReleaseCOM(_sheets);
ReleaseCOM(_book);
ReleaseCOM(_books);
_excelApp.Quit();
ReleaseCOM(_excelApp);
return sheetName;
}
开发者ID:wybq68,项目名称:DIH_LUMBARROBAT,代码行数:25,代码来源:ExcelHelper.cs
示例6: btnGenerate_Click
private void btnGenerate_Click(object sender, EventArgs e)
{
//string filename = "Azure_Pass_Account" +/* datePicker.ToString() + */inputApplicant.Text;
Excel.Application excel = new Excel.Application();
excel.Visible = true;
Excel.Workbook wb = excel.Workbooks.Add(1);
Excel.Worksheet sh = wb.Sheets.Add();
datePicker.Format = DateTimePickerFormat.Custom;
datePicker.CustomFormat = "yyMMdd";
sh.Name = "Azure Account";
sh.Cells[1, "A"].Value2 = "Index";
sh.Cells[1, "B"].Value2 = "Account";
sh.Cells[1, "C"].Value2 = "Password";
sh.Cells[1, "D"].Value2 = "Applicant";
for(int index = 1; index <= Int32.Parse( inputAmount.Text); index ++)
{
sh.Cells[index + 1 ,"A"].Value2 = index;
sh.Cells[index + 1, "B"].Value2 = "MS" + datePicker.Text + index.ToString("000") + "@outlook.com";
sh.Cells[index + 1, "C"].Value2 = "MS" + datePicker.Text;
sh.Cells[index + 1, "D"].Value2 = inputApplicant.Text;
}
string filename = "Azure_Pass_Account_" + datePicker.Text + "_" + inputApplicant.Text + "_Auto_Generate";
SaveFileDialog mySaveFileDialog = new SaveFileDialog();
mySaveFileDialog.FileName = filename;
mySaveFileDialog.Filter = "Excel files (*.xlsx)|*.xlsx";
mySaveFileDialog.ShowDialog();
excel.Quit();
}
开发者ID:4lenz1,项目名称:OutlookAccountGenerator,代码行数:33,代码来源:Form1.cs
示例7: PluginManager
/// <summary/>
public PluginManager( MSExcel.Application application )
{
myApplication = application;
myPluginContext = new PluginContext( myApplication );
myPlugins = new List<AbstractPlugin>();
}
开发者ID:bg0jr,项目名称:Maui,代码行数:8,代码来源:PluginManager.cs
示例8: excel
public excel()
{
var excel = new Excel.Application();
//OR
/*
Type ExcelType = Type.GetTypeFromProgID("Excel.Application");
dynamic excel = Activator.CreateInstance(ExcelType);
*/
var workbook = excel.Workbooks.Add();
var sheet = excel.ActiveSheet;
excel.Visible = true;
excel.Cells[1, 1] = "Hi from Me";
excel.Columns[1].AutoFit();
excel.Cells[2,1]=10;
excel.Cells[3, 1] = 10;
excel.Cells[4, 1] = 20;
excel.Cells[5, 1] = 30;
excel.Cells[6, 1] = 40;
excel.Cells[7, 1] = 50;
excel.Cells[8, 1] = 60;
var chart = workbook.Charts.Add(After:sheet);
chart.ChartWizard(Source:sheet.Range("A2","A7"));
}
开发者ID:saeidghoreshi,项目名称:partition1,代码行数:27,代码来源:excel.cs
示例9: Init
private void Init()
{
xlApp = new Excel.Application();
xlWorkBook = xlApp.Workbooks.Open(name, 0, true, 5, "", "", true, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "\t", false, false, 0, true, 1, 0);
xlSh = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);
}
开发者ID:NextStalker,项目名称:RegionalReport,代码行数:7,代码来源:OfficeDoc.cs
示例10: CopyToClipboardButton_Click
private void CopyToClipboardButton_Click(object sender, EventArgs e)
{
if (EmailResultTextBox.Text.Length == 0)
{
return;
}
Microsoft.Office.Interop.Excel.Application excelApp = new Microsoft.Office.Interop.Excel.Application();
excelApp.Visible = true;
_Workbook workbook = (_Workbook)(excelApp.Workbooks.Add(Type.Missing));
_Worksheet worksheet = (_Worksheet)workbook.ActiveSheet;
TicketRepository ticketRepo = new TicketRepository();
List<TicketResource> listOfTickets = ticketRepo.GetDistinctEmailAddressBetweenDates(StartingDatePicker.Value, EndingDatePicker.Value);
for (int i = 0; i < listOfTickets.Count; i++)
{
TicketResource ticket = listOfTickets[i];
int row = i + 1;
worksheet.Cells[row, "A"] = ticket.LastName;
worksheet.Cells[row, "B"] = ticket.FirstName;
worksheet.Cells[row, "C"] = ticket.Email;
}
worksheet.Columns["A:C"].AutoFit();
}
开发者ID:jpark822,项目名称:HKT,代码行数:25,代码来源:AdminStatsForm.cs
示例11: CallMacro
public void CallMacro(string file)
{
Excel.Application xlApp;
Workbook xlWorkBook;
Worksheet xlWorkSheet;
object misValue = System.Reflection.Missing.Value;
xlApp = new Excel.Application();
xlWorkBook = xlApp.Workbooks.Open(file);//, 0, true, 5, "", "", true, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "\t", false, false, 0, true, 1, 0);
xlWorkSheet = (Microsoft.Office.Interop.Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);
xlWorkSheet
MessageBox.Show(xlWorkSheet.get_Range("A1", "A1").Value2.ToString());
RunMacro(
xlWorkBook.Close(true, misValue, misValue);
xlApp.Quit();
// Application.Run "PERSONAL.XLSB!CleanDocket"
//Application.Run "PERSONAL.XLSB!Create_Upcoming_Docket"
//Sheets("Upcoming Hearings").Select
//Sheets("Upcoming Hearings").Move Before:=Sheets(1)
/*
*
*
releaseObject(xlWorkSheet);
releaseObject(xlWorkBook);
releaseObject(xlApp);*/
}
开发者ID:amirbey,项目名称:DocToSoc,代码行数:28,代码来源:~AutoRecover.DocSoc.cs
示例12: btnExport_Click
private void btnExport_Click(object sender, EventArgs e)
{
try
{
SaveFileDialog sfd = new SaveFileDialog();
Microsoft.Office.Interop.Excel.Application myExcelFile = new Microsoft.Office.Interop.Excel.Application();
sfd.Title = "Save As";
sfd.Filter = "Microsoft Excel|*.xlsx";
sfd.DefaultExt = "xlsx";
if (sfd.ShowDialog() == DialogResult.OK)
{
Workbook myWorkBook = myExcelFile.Workbooks.Add(XlSheetType.xlWorksheet);
Worksheet myWorkSheet = (Worksheet)myExcelFile.ActiveSheet;
// don't open excel file in windows during building
myExcelFile.Visible = false;
label1.Text = "Building the excel file. Please wait...";
// set the first row cells as column names according to the names of data grid view columns names
foreach (DataGridViewColumn dgvColumn in dataGridView.Columns)
{
// dataGridView columns is a zero-based array, while excel sheet is a 1-based array
// so, first row of excel sheet has index 1
// set columns of first row as titles of columns
myWorkSheet.Cells[1, dataGridView.Columns.IndexOf(dgvColumn) + 1] = dgvColumn.HeaderText;
}
// since, first row has titles that are set above, start from row-2 and fill each row of excel file.
for (int i = 2; i <= dataGridView.Rows.Count; i++)
{
for (int j = 0; j < dataGridView.Columns.Count; j++)
{
myWorkSheet.Cells[i, j + 1] = dataGridView.Rows[i - 2].Cells[j].Value;
}
}
// set the font style of first row as Bold which has titles of each column
myWorkSheet.Rows[1].Font.Bold = true;
myWorkSheet.Rows[1].Font.Size = 12;
// after filling, save the file to the specified location
string savePath = sfd.FileName;
myWorkBook.SaveCopyAs(savePath);
}
label1.Text = "File saved successfully.";
if (MessageBox.Show("File saved successfully. Do you want to open it now?", "File Saved!", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
myExcelFile.Visible = true;
}
}
catch(Exception exc)
{
label1.Text = exc.Message;
}
}
开发者ID:mhsohail,项目名称:Authors,代码行数:60,代码来源:Form1.cs
示例13: ReadDataSet
public ReportDataSet ReadDataSet(string file, int headerRowNumber)
{
ReportDataSet dataSet = new ReportDataSet();
try
{
excel = new Excel.Application();
Excel.Workbook tempBook = excel.Workbooks.Open(file);
foreach (var item in tempBook.Sheets)
{
Excel.Worksheet sheet = item as Excel.Worksheet;
ReportDataTable table = this.GetDataTable(sheet, headerRowNumber);
dataSet.Tables.Add(table.Name, table);
}
tempBook.Save();
tempBook.Close();
tempBook = null;
excel.Application.Quit();
}
catch (Exception ex)
{
excel.Application.Quit();
}
return dataSet;
}
开发者ID:TonyWu,项目名称:QvSubscriber,代码行数:27,代码来源:ReportDataReader.cs
示例14: DocSoc
public DocSoc()
{
string reportsFile = System.Configuration.ConfigurationManager.AppSettings["ReportsFile"];
string macrosFile = System.Configuration.ConfigurationManager.AppSettings["MacrosFile"];
System.IO.FileInfo macrosFileInfo = new System.IO.FileInfo(macrosFile);
Hashtable reportsHash = readReportsXML(reportsFile,macrosFileInfo.Name);
string[] reportsSelected = getSelectedReports(reportsHash);
Excel.Application xlApp;
Excel.Workbook macroBook = null;
xlApp = new Excel.Application();
Console.Write("Excel opened");
try
{
macroBook = xlApp.Workbooks.Open(macrosFileInfo.FullName);
Console.WriteLine("MacroFile opened: " + macrosFileInfo.FullName);
this.processReports(xlApp, reportsHash, reportsSelected);
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
System.Windows.Forms.MessageBox.Show("DocToSoc failed while processing reports.", "DocToSoc Failed", System.Windows.Forms.MessageBoxButtons.OK);
}
finally
{
macroBook.Close();
Console.WriteLine("MacroWorkBook closed: " + macrosFile);
xlApp.Quit();
Console.WriteLine("Excel Closed");
}
}
开发者ID:amirbey,项目名称:DocToSoc,代码行数:34,代码来源:DocSoc.cs
示例15: read
public void read(ref List<string> grpname , ref List<string> path)
{
createfile objcf = new createfile();
Excel.Application xlApp;
Excel.Workbook xlWorkBook;
Excel.Worksheet xlWorkSheet;
Excel.Range range;
object missing = System.Reflection.Missing.Value;
xlApp = new Excel.Application();
xlWorkBook = xlApp.Workbooks.Open(@"d:\database\Group.xlsx", 0, false, 5, "", "", true, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "\t", true, true, 0, true, 1, 0);
xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);
range = xlWorkSheet.UsedRange;
int i = 0;
string str,str1;
for (int rCnt = 1; rCnt <= range.Rows.Count; rCnt++)
{
str = (string)(range.Cells[rCnt, 1] as Excel.Range).Value2;
str1 = (string)(range.Cells[rCnt, 2] as Excel.Range).Value2;
grpname.Add(str);
path.Add(str1);
}
xlWorkBook.Close(true, null, null);
xlApp.Quit();
objcf.releaseObject(xlWorkSheet);
objcf.releaseObject(xlWorkBook);
objcf.releaseObject(xlApp);
}
开发者ID:RohitTiwari92,项目名称:Connect-with-one-click,代码行数:31,代码来源:readGroupFile.cs
示例16: OldWay
//C# 4.0 미만에서 COM컴포넌트 사용하는 코드
public static void OldWay(string[,] data, string savePath)
{
Excel.Application excelApp = new Excel.Application();
//의미없는 매개변수 입력
excelApp.Workbooks.Add(Type.Missing);
//형변환
Excel.Worksheet workSheet = (Excel.Worksheet)excelApp.ActiveSheet;
for (int i = 0; i < data.GetLength(0); i++)
{
//형변환
((Excel.Range)workSheet.Cells[i + 1, 1]).Value2 = data[i, 0];
((Excel.Range)workSheet.Cells[i + 1, 2]).Value2 = data[i, 1];
}
//의미없는 매개변수 입력
workSheet.SaveAs(savePath + "\\addressbook-old.xlsx",
Type.Missing,
Type.Missing,
Type.Missing,
Type.Missing,
Type.Missing,
Type.Missing,
Type.Missing,
Type.Missing);
excelApp.Quit();
}
开发者ID:10zeroone,项目名称:study_csharp,代码行数:31,代码来源:MainApp.cs
示例17: Workbook
public Workbook(Excel.Workbook wb, Excel.Application app, Action dispose_callback)
{
_app = app;
_wb = wb;
_wb_name = wb.Name;
_dispose_callback = dispose_callback;
}
开发者ID:dbarowy,项目名称:Depends,代码行数:7,代码来源:Workbook.cs
示例18: LoadandMatchMetricsNames
public LoadandMatchMetricsNames(String dashboardFile)
{
try
{
app = new Excel.Application();
app.Visible = true;
dashboard = app.Workbooks.Open(dashboardFile,
Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing);
/* for (int i = 0; i < metricsFiles.Length; i++)
{
metrics = app.Workbooks.Open(metricsFiles[i],
Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing);
//this is where we read all the data into some sort of array
//ExcelScanInternal(metrics);
metrics.Close(false, metricsFiles[i], null);
} */
//cleanup
//dashboard.Close(false, dashboardFile, null);
}
catch (Exception ex) { Console.WriteLine(ex.Message); }
}
开发者ID:secgoat,项目名称:Dashboards,代码行数:31,代码来源:LoadandMatchMetricsNames.cs
示例19: DTToExcel
public void DTToExcel(DataTable dt, string filename)
{
object[,] t = DataTableTo2DTable(dt);
excel.Application eapp = new excel.Application();
excel.Workbook book = eapp.Workbooks.Add();
excel.Worksheet sheet = book.Worksheets[1];
sheet.Range["A1", sheet.Cells[t.GetLength(0), t.GetLength(1)]].Value = t;
if (t.GetLength(0) > 1)
{
for (int j = 0; j < t.GetLength(1); j++)
{
if (dt.Columns[j].DataType == typeof(DateTime))
{
sheet.Range[sheet.Cells[2, j + 1], sheet.Cells[t.GetLength(0), j + 1]].NumberFormat = "yyyy/m/d h:mm";
}
}
}
//for (int i = 0; i < dt.Rows.Count; i++)
//{
// for (int j = 0; j < dt.Columns.Count; j++)
// {
// sheet.Cells[j + 1][i + 1] = dt.Rows[i][j];
// }
//}
book.SaveAs(filename);
eapp.Visible = true;
}
开发者ID:xiexi1990,项目名称:Audit,代码行数:28,代码来源:DataTableHelper.cs
示例20: button1_Click
private void button1_Click(object sender, EventArgs e)
{
MyApp = new Excel.Application();
MyApp.Visible = false;
MyBook = MyApp.Workbooks.Open(path);
MySheet = (Excel.Worksheet)MyBook.Sheets[1];
lastrow = MySheet.Cells.SpecialCells(Excel.XlCellType.xlCellTypeLastCell).Row;
BindingList<Dompet> DompetList = new BindingList<Dompet>();
for (int index = 2; index <= lastrow; index++)
{
System.Array MyValues =
(System.Array)MySheet.get_Range
("A" + index.ToString(),"F" + index.ToString()).Cells.Value;
DompetList.Add(new Dompet {
JmlPemesanan = MyValues.GetValue(1,1).ToString(),
JmlPekerja = MyValues.GetValue(1,2).ToString(),
Peralatan = MyValues.GetValue(1,3).ToString(),
JenisKulit = MyValues.GetValue(1,4).ToString(),
ModelDompet = MyValues.GetValue(1,5).ToString(),
Prediksi = MyValues.GetValue(1,6).ToString()
});
}
dataGridView1.DataSource = (BindingList<Dompet>)DompetList;
dataGridView1.AutoResizeColumns();
}
开发者ID:renandatta,项目名称:NaiveBayes,代码行数:27,代码来源:FrmMain.cs
注:本文中的Microsoft.Office.Interop.Excel.Application类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论