本文整理汇总了C#中Microsoft.Office.Interop.Excel.Workbook类的典型用法代码示例。如果您正苦于以下问题:C# Workbook类的具体用法?C# Workbook怎么用?C# Workbook使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Workbook类属于Microsoft.Office.Interop.Excel命名空间,在下文中一共展示了Workbook类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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);
}
示例2: reporttoexcel_clients
public void reporttoexcel_clients(List<string> station_name_list, List<int> station_turnover_list, List<int> station_avg_list)
{
Eapp.Visible = true;
string path = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
book = Eapp.Workbooks.Open(path + @"\отчет_клиента_шаблон.xlsx");
excel.Worksheet sheet = (excel.Worksheet)book.Worksheets.get_Item(1);
excel.Range range_sheet = sheet.UsedRange;
for (int i = 2; i < station_name_list.Count + 2; i++)
{
excel.Range range_cur = range_sheet.Cells[i, 1];
range_cur.Value2 = station_name_list[i - 2];
range_cur = range_sheet.Cells[i, 2];
range_cur.Value2 = station_turnover_list[i - 2];
range_cur = range_sheet.Cells[i, 3];
range_cur.Value2 = station_avg_list[i - 2];
}
book.SaveAs(path + @"\reports\отчет_клиента.xlsx");
Eapp.Quit();
}
示例3: Form1_Load
//加载
private void Form1_Load(object sender, EventArgs e)
{
panel1.Visible = false;
app = new MSExcel.Application();
app.Visible = false;
book = app.Workbooks.Open(@"D:\template.xls");
sheet = (MSExcel.Worksheet)book.ActiveSheet;
//串口设置默认选择项
cbSerial.SelectedIndex = 1; //note:获得COM9口,但别忘修改
cbBaudRate.SelectedIndex = 5;
cbDataBits.SelectedIndex = 3;
cbStop.SelectedIndex = 0;
cbParity.SelectedIndex = 0;
//sp1.BaudRate = 9600;
Control.CheckForIllegalCrossThreadCalls = false; //这个类中我们不检查跨线程的调用是否合法(因为.net 2.0以后加强了安全机制,,不允许在winform中直接跨线程访问控件的属性)
sp1.DataReceived += new SerialDataReceivedEventHandler(sp1_DataReceived);
//sp1.ReceivedBytesThreshold = 1;
radio1.Checked = true; //单选按钮默认是选中的
rbRcvStr.Checked = true;
//准备就绪
sp1.DtrEnable = true;
sp1.RtsEnable = true;
//设置数据读取超时为1秒
sp1.ReadTimeout = 1000;
sp1.Close();
}
示例4: openXL
public static void openXL(string xlp)
{
xla = new Excel.Application();
xlw = xla.Workbooks.Open(xlp);
xls = xlw.Worksheets.get_Item(1);
xlr = xls.UsedRange;
}
示例5: ReadProcesses
public void ReadProcesses()
{
count = 0;
ExcelApp = new Excel.Application();
ExcelApp.Visible = false;
WorkBookExcel = ExcelApp.Workbooks.Open(_filePath, false); //открываем книгу
//Читаем данные по проектам
WorkSheetExcel = (Excel.Worksheet)WorkBookExcel.Sheets["Processes"]; //Получаем ссылку на лист Processes
List<string> row = new List<string>();
int n = 6;
for (int i = 2; WorkSheetExcel.Cells[i, 1].Text.ToString() != ""; i++)
{
row = new List<string>();
for (int j = 1; j < n; j++) row.Add(WorkSheetExcel.Cells[i, j].Text.ToString()); //строка массива заполняется просто суммой i и j
Mas.Add(row); //строка добавляется в массив
count++;
}
//test = WorkSheetExcel.Cells[2, 1];
WorkBookExcel.Close(false, Type.Missing, Type.Missing);
ExcelApp.Quit();
GC.Collect();
}
示例6: ComExportExcel
public ComExportExcel(string templatePath)
{
xlApp = new ComExcel.Application();
xlWorkBook = xlApp.Workbooks.Open(templatePath, 0, false, 5, "", "", true, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "\t", true, false, 0, true, 1, 0);
//xlWorkBook = xlApp.Workbooks.Open(templatePath, ReadOnly:false, Editable:true );
xlWorkSheet = (ComExcel.Worksheet)xlWorkBook.Worksheets.get_Item(1);
}
示例7: Main
static void Main(string[] args)
{
//GetSPList("http://sharepoint/sites/fim/ISV9-3", "v-jianzh", "isnes21)$MAM", "fareast.corp.microsoft.com");
//foreach (ListItem listItem in listItems)
//{
// Console.WriteLine("ID:{0} Application Name:{1}", listItem.Id, listItem["Application_x0020_Name"].ToString());
//}
xApp = new Excel.Application();
xApp.Visible = true;
xbook = xApp.Workbooks.Open("C:\\share\\temp.xlsx");
GetVisibleFormExcel();
//for (int i = 0; i < nameArr.Count;i++ )
//{
// Console.WriteLine("Name:{0} IE:{1} FireFox:{2} Chrome:{3}", nameArr[i],ieArr[i],firefoxArr[i],chromeArr[i]);
//}
UpdateToMasterList();
xbook = null; xApp.Quit(); xApp = null;
Console.ReadLine();
}
示例8: GetDataFromExcel
/// <exception cref="FileNotFoundException"><c>FileNotFoundException</c>.</exception>
/// <exception cref="Exception"><c>Exception</c>.</exception>
public IList<IDataRecord> GetDataFromExcel(string filePath)
{
try
{
Log.Info("Начало импорта");
if (!File.Exists(filePath))
throw new FileNotFoundException(string.Format("Файл не найден. [{0}]", filePath));
Excelapp = new Application { Visible = false };
Workbook = Excelapp.Workbooks.Open(filePath, 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);
ReadDoc();
}
catch( Exception e)
{
Log.Error("Ошибка импорта", e);
throw;
}
finally
{
Workbook.Close();
Excelapp.Quit();
Excelapp = null;
}
return DataRecords;
}
示例9: InitializePlanGenerator
/// <summary>
/// Function for initializing access to and validating the resources found in the given directory.
/// </summary>
public void InitializePlanGenerator()
{
//A message of where the resource files are located
Console.WriteLine("EventFiles: " + resourcepath);
try
{
//Initialize excel accesser class
excel = new Excel.Application();
//Path to the excel sheet is created
var excelSheetPath = Path.GetFullPath(resourcepath);
//The excel arc found at the resource path is opened and a gateway is initialized
//TODO: create a system for choosing the correct file
CurrentWorkBook = excel.Workbooks.Open(excelSheetPath);
//The plangenerationhandler function is called
PlanGenerationHandler();
}
catch (Exception) { }
finally
{
EvalMessage();
//COM objects countermeasure - this is needed for the excel processes to be closed
Process[] excelProcs = Process.GetProcessesByName("EXCEL");
foreach (Process proc in excelProcs)
{
proc.Kill();
}
}
}
示例10: InitializeExcel
public static void InitializeExcel()
{
_myApp = new Excel.Application {Visible = false};
_myBook = _myApp.Workbooks.Open(ExcelPath);
_mySheet = (Excel.Worksheet)_myBook.Sheets[1]; // Explict cast is not required here
_lastRow = _mySheet.Cells.SpecialCells(Excel.XlCellType.xlCellTypeLastCell).Row;
}
示例11: Form1_Load
private void Form1_Load(object sender, EventArgs e)
{
app = new Excel.Application();
app.Visible = false;
workbook = app.Workbooks.Open(Application.StartupPath + "\\Дни рождения сотрудников.xls");
worksheet = workbook.ActiveSheet;
int i = 0;
string today = DateTime.Now.ToString("dd.MM");
string tomorrow = DateTime.Now.AddDays(1).ToString("dd.MM");
for (i = 1; i <= worksheet.UsedRange.Rows.Count; i++)
{
if (worksheet.Cells[2][i].Value == "Іб та ПД" || worksheet.Cells[3][i].Value == "Іб та ПД" || worksheet.Cells[2][i].Value == "Інформаційної безпеки та передачі даних" || worksheet.Cells[3][i].Value == "Інформаційної безпеки та передачі даних")
{
string birthday = worksheet.Cells[4][i].Value.ToString("dd.MM");
if (birthday == today)
{
label1.Text = "";
label1.Text += "Сегодня свой день рождения отмечает " + worksheet.Cells[1][i].Value;
}
if (birthday == tomorrow)
{
label1.Text = "";
label1.Text += "Завтра свой день рождения отмечает " + worksheet.Cells[1][i].Value;
}
}
}
app.Quit();
}
示例12: export
public void export()
{
try
{
//excelApp = (Excel.Application)Marshal.GetActiveObject("Excel.Application");
//wb = excelApp.Workbooks.Add();
wb = (Excel.Workbook)Globals.ThisAddIn.Application.ActiveWorkbook;
ws = wb.Worksheets.get_Item(1) as Excel.Worksheet;
// 데이타 넣기
int r = 1;
foreach (var d in this.exceptionList_)
{
ws.Cells[r, 1] = d.Message;
r++;
}
//this.wb.Worksheets.Add(ws);
}
finally
{
// Clean up
ReleaseExcelObject(ws);
ReleaseExcelObject(wb);
ReleaseExcelObject(excelApp);
}
}
示例13: TaskPriority
public TaskPriority()
{
InitializeComponent();
missing = System.Reflection.Missing.Value;
config_data.ConfigFile = Environment.GetEnvironmentVariable("USERPROFILE")+"\\IntCallBack.xls";
xlApp = new msexcel.Application();
time_wasting = false;
if (File.Exists(config_data.ConfigFile))
{
xlWorkBook = xlApp.Workbooks.Open(config_data.ConfigFile, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing);
xlWorkSheet = (msexcel.Worksheet) xlWorkBook.Worksheets.get_Item(1);
double dummy = (double) (xlWorkSheet.Cells[1, 2] as msexcel.Range ).Value ;
config_data.PopUp = ((int)dummy == 1) ? true : false;
config_data.RFrequency = (int)(xlWorkSheet.Cells[2, 2] as msexcel.Range).Value;
config_data.Urgent_Hrs = (int)(xlWorkSheet.Cells[3, 2] as msexcel.Range).Value;
config_data.Urgent_Mins = (int)(xlWorkSheet.Cells[4, 2] as msexcel.Range).Value;
config_data.task1 = (string) (xlWorkSheet.Cells[5, 2] as msexcel.Range).Value;
config_data.task2 = (string)(xlWorkSheet.Cells[6, 2] as msexcel.Range).Value;
config_data.task3 = (string)(xlWorkSheet.Cells[7, 2] as msexcel.Range).Value;
config_data.task4 = (string)(xlWorkSheet.Cells[8, 2] as msexcel.Range).Value;
re_load_flag = true;
}
else
{
xlWorkBook = xlApp.Workbooks.Add(missing);
xlWorkSheet = xlWorkBook.Worksheets.get_Item(1);
config_data.PopUp = true;
config_data.RFrequency = 3;
config_data.Urgent_Hrs = 8;
config_data.Urgent_Mins = 0;
config_data.task1 = config_data.task2 = config_data.task3 = config_data.task4 = "";
xlWorkSheet.Cells[1, 1] = "PopUP";
xlWorkSheet.Cells[2, 1] = "Frequency";
xlWorkSheet.Cells[3, 1] = "Urgent Hrs";
xlWorkSheet.Cells[4, 1] = "Urgent Mins";
xlWorkSheet.Cells[5,1] = "Task 1";
xlWorkSheet.Cells[6,1] = "Task 2";
xlWorkSheet.Cells[7,1] = "Task 3";
xlWorkSheet.Cells[8,1] = "Task 4";
xlWorkSheet.Cells[1, 2] = (config_data.PopUp == true) ? "1" : "2";
xlWorkSheet.Cells[2, 2] = config_data.RFrequency.ToString();
xlWorkSheet.Cells[3, 2] = config_data.Urgent_Hrs.ToString();
xlWorkSheet.Cells[4, 2] = config_data.Urgent_Mins.ToString();
xlWorkSheet.Cells[5, 2] = config_data.task1;
xlWorkSheet.Cells[6, 2] = config_data.task1;
xlWorkSheet.Cells[7, 2] = config_data.task1;
xlWorkSheet.Cells[8, 2] = config_data.task1;
xlWorkBook.SaveAs(config_data.ConfigFile, msexcel.XlFileFormat.xlWorkbookNormal, missing, missing, missing, missing, msexcel.XlSaveAsAccessMode.xlShared, missing, missing, missing, missing, missing);
//xlWorkBook.Close();
re_load_flag = false;
}
}
示例14: ClusteringManager
public ClusteringManager()
{
//prepare Excel objects:
m_ObjExcel = new Microsoft.Office.Interop.Excel.Application();
m_ObjWorkBook = m_ObjExcel.Workbooks.Open(
MethodInputResponse.INPUT_FILE_PATH,
0,
false,
5,
"",
"",
false,
Microsoft.Office.Interop.Excel.XlPlatform.xlWindows,
"",
true,
false,
0,
true,
false,
false);
m_ObjWorkSheet1 = (myExcel.Worksheet)m_ObjWorkBook.Sheets[1];
myExcel.Sheets xlSheets = m_ObjWorkBook.Sheets as myExcel.Sheets;
for (int i = 3; i < MAX_CLUSTERS_NUMBER; i++)
{
xlSheets.Add(Type.Missing, m_ObjWorkSheet1, Type.Missing, Type.Missing);
}
}
示例15: GroupByVertexAttributeDialog
//*************************************************************************
// Constructor: GroupByVertexAttributeDialog()
//
/// <overloads>
/// Initializes a new instance of the <see
/// cref="GroupByVertexAttributeDialog" /> class.
/// </overloads>
///
/// <param name="workbook">
/// Workbook containing the graph contents.
/// </param>
//*************************************************************************
public GroupByVertexAttributeDialog(
Microsoft.Office.Interop.Excel.Workbook workbook
)
{
InitializeComponent();
m_oWorkbook = workbook;
// Instantiate an object that saves and retrieves the user settings for
// this dialog. Note that the object automatically saves the settings
// when the form closes.
m_oGroupByVertexAttributeDialogUserSettings =
new GroupByVertexAttributeDialogUserSettings(this);
if ( ExcelUtil.TryGetTable(m_oWorkbook, WorksheetNames.Vertices,
TableNames.Vertices, out m_oVertexTable) )
{
cbxVertexColumnName.PopulateWithTableColumnNames(m_oVertexTable);
}
cbxVertexColumnFormat.PopulateWithObjectsAndText(
ExcelColumnFormat.Other, "Categories",
ExcelColumnFormat.Number, "Numbers",
ExcelColumnFormat.Date, "Dates",
ExcelColumnFormat.Time, "Times",
ExcelColumnFormat.DateAndTime, "Dates with times"
);
DoDataExchange(false);
AssertValid();
}