本文整理汇总了C#中Microsoft.Office.Interop.Excel.Workbook类的典型用法代码示例。如果您正苦于以下问题:C# Workbook类的具体用法?C# Workbook怎么用?C# Workbook使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Workbook类属于Microsoft.Office.Interop.Excel命名空间,在下文中一共展示了Workbook类的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: 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();
}
开发者ID:Alexanderexe,项目名称:course_Project,代码行数:34,代码来源:COM_out.cs
示例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();
}
开发者ID:Jamescaiyy,项目名称:SerialPort,代码行数:36,代码来源:Form1.cs
示例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;
}
开发者ID:gluefish,项目名称:WatiX-cs-U,代码行数:7,代码来源:ExcelUtils.cs
示例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();
}
开发者ID:Samoykin,项目名称:TimeCounter,代码行数:26,代码来源:DataFromXls.cs
示例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);
}
开发者ID:vuchannguyen,项目名称:lg-py,代码行数:7,代码来源:ComExportExcel.cs
示例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();
}
开发者ID:LeonZhang77,项目名称:Tools,代码行数:25,代码来源:Program.cs
示例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;
}
开发者ID:pvx,项目名称:ShopOrder,代码行数:30,代码来源:ExcelImport.cs
示例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();
}
}
}
开发者ID:DeStuderendesErhvervskontakt,项目名称:ProjectPlanner,代码行数:35,代码来源:ControlPanel.cs
示例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;
}
开发者ID:lilvonz,项目名称:SchoolAccountant,代码行数:7,代码来源:ExcelHelper.cs
示例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();
}
开发者ID:phobos-nik,项目名称:academy,代码行数:31,代码来源:Form1.cs
示例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);
}
}
开发者ID:minikie,项目名称:test,代码行数:28,代码来源:ExcelExport.cs
示例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;
}
}
开发者ID:Dhilip-Kumar-S,项目名称:InterruptCallBack,代码行数:60,代码来源:Form1.cs
示例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);
}
}
开发者ID:osnihur,项目名称:clustering,代码行数:28,代码来源:ClusteringManager.cs
示例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();
}
开发者ID:haisreekanth,项目名称:NetMap,代码行数:45,代码来源:GroupByVertexAttributeDialog.cs
示例16: StudentWorkbook
/// <summary>
/// Class constructor does all the work
/// </summary>
/// <param name="excelApp"></param>
/// <param name="fileName"></param>
public StudentWorkbook( Excel.Application excelApp, string fileName )
{
try // to open the student's spreadsheet
{
excelWorkbook = excelApp.Workbooks.Open( fileName, 0,
true, 5, "", "", false, Excel.XlPlatform.xlWindows, "", true, // read only
false, 0, true, false, false );
}
catch ( Exception e )
{
Console.WriteLine( "error: " + e.Message );
Console.WriteLine( "Could not open spreadsheet " + fileName );
}
Excel.Sheets excelSheets = excelWorkbook.Worksheets; // get the Worksheets collection
Excel.Worksheet excelWorksheet = excelSheets[ 1 ]; // get the first one
// get the Team Number cell
Excel.Range excelCell = (Excel.Range)excelWorksheet.get_Range( "B4", "B4" );
// try to convert this cell to an integer
if ( ( teamNumber = TryForInt( excelCell.Value ) ) == 0 )
{
Console.WriteLine( "\nTeam number invalid in " + fileName + "\n" );
}
// get the scores cells
scores = excelWorksheet.get_Range( "B7", "B15" );
// get the Additional Comments cell
comments = excelWorksheet.get_Range( "B18", "B18" );
} // end of StudentWorkbook()
开发者ID:cyboss77,项目名称:ClassAssessments,代码行数:38,代码来源:StudentWorkbook.cs
示例17: 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
示例18: 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
示例19: ExcelHelper
public ExcelHelper(string _filePath)
{
filePath = _filePath;
excelApp = new Excel.Application();
object objOpt = System.Reflection.Missing.Value;
wbclass = (Excel.Workbook)excelApp.Workbooks.Open(_filePath, objOpt, false, objOpt, objOpt, objOpt, true, objOpt, objOpt, true, objOpt, objOpt, objOpt, objOpt, objOpt);
}
开发者ID:cqpaul,项目名称:Tools,代码行数:7,代码来源:ExcelHelper.cs
示例20: 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
注:本文中的Microsoft.Office.Interop.Excel.Workbook类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论