public String Version() { using (var excel = new NetOffice.ExcelApi.Application()) { var version = excel.Version; excel.Quit(); return version; } }
public MainWindow() { InitializeComponent(); using (var excelApplication = new NetOffice.ExcelApi.Application()) { try { // Création du fichier de travail. var workBook = excelApplication.Workbooks.Add(); // Positionnement sur le premier onglet. var workSheet = (NetOffice.ExcelApi.Worksheet)workBook.Worksheets[1]; // Ajout des données dans les différentes cellules. workSheet.Cells[1, 2].Value = "Langues (en millions de locuteurs) :"; workSheet.Cells[2, 1].Value = "Mandarin"; workSheet.Cells[2, 2].Value = "860"; workSheet.Cells[3, 1].Value = "Espagnol"; workSheet.Cells[3, 2].Value = "469"; workSheet.Cells[4, 1].Value = "Anglais"; workSheet.Cells[4, 2].Value = "362"; workSheet.Cells[5, 1].Value = "Arabe"; workSheet.Cells[5, 2].Value = "276"; workSheet.Cells[6, 1].Value = "Bengali"; workSheet.Cells[6, 2].Value = "270"; workSheet.Cells[7, 1].Value = "Hindi"; workSheet.Cells[7, 2].Value = "269"; workSheet.Cells[8, 1].Value = "Portugais"; workSheet.Cells[8, 2].Value = "222"; workSheet.Cells[9, 1].Value = "Russe"; workSheet.Cells[9, 2].Value = "150"; workSheet.Cells[10, 1].Value = "Japonais"; workSheet.Cells[10, 2].Value = "125"; workSheet.Cells[11, 1].Value = "Lahnda/Pendjabi"; workSheet.Cells[11, 2].Value = "112"; // Ajout d'un diagramme et positionnement. var chart = ((NetOffice.ExcelApi.ChartObjects)workSheet.ChartObjects()).Add(150, 200, 500, 400); // Définition du type de diagramme. chart.Chart.ChartType = NetOffice.ExcelApi.Enums.XlChartType.xlPie; // Association du diagramme aux données de la grille. chart.Chart.SetSourceData(workSheet.Range("A1:B11")); // Enregistrement du fichier. workBook.SaveAs(@"C:\Users\toky\Desktop\newDep\test.xlsx"); } finally { // Sortie de l'application Excel. excelApplication.Quit(); } } }
private static void Verify0000001002560(string filename) { using (var excel = new NetOffice.ExcelApi.Application()) { var workBook = excel.Workbooks.Open(filename); var workSheet = (NetOffice.ExcelApi.Worksheet)workBook.Worksheets[1]; Assert.AreEqual("reading.test", workSheet.Cells[2, 1].Value); Assert.AreEqual("読み込みテスト", workSheet.Cells[2, 2].Value); excel.Quit(); } }
public void CreateReport(string outFilePath) { using (var excelApp = new NetOffice.ExcelApi.Application()) { excelApp.DisplayAlerts = false; var workbook = excelApp.Workbooks.Add(); CreateCompetitorListWorksheet(workbook.Worksheets[1] as NetOffice.ExcelApi.Worksheet); CreateSpectatorListWorksheet(workbook.Worksheets.Add(Type.Missing, workbook.Worksheets[workbook.Worksheets.Count]) as NetOffice.ExcelApi.Worksheet); CreateRefereeListWorksheet(workbook.Worksheets.Add(Type.Missing, workbook.Worksheets[workbook.Worksheets.Count]) as NetOffice.ExcelApi.Worksheet); CreateCoachListWorksheet(workbook.Worksheets.Add(Type.Missing, workbook.Worksheets[workbook.Worksheets.Count]) as NetOffice.ExcelApi.Worksheet); CreateSparringListWorksheet(workbook.Worksheets.Add(Type.Missing, workbook.Worksheets[workbook.Worksheets.Count]) as NetOffice.ExcelApi.Worksheet); CreateFormsListWorksheet(workbook.Worksheets.Add(Type.Missing, workbook.Worksheets[workbook.Worksheets.Count]) as NetOffice.ExcelApi.Worksheet); workbook.SaveAs(outFilePath); excelApp.Quit(); } }
public void Register() { var app = new NetOffice.ExcelApi.Application(); var version = app.Version; app.Quit(); var key = Registry.CurrentUser.OpenSubKey($"Software\\Microsoft\\Office\\{version}\\Excel\\Options", true); if (key == null) { return; } var allChildValues = key.GetValueNames(); // check if the plug-in is already installed... var openValues = allChildValues.Where(v => v.StartsWith("OPEN")).ToList(); if (openValues.Any(v => key.GetValue(v).ToString().Contains(registerName))) { return; } var path = InstallationPath; if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } var xllToRegister = $"{path}\\{registerName}"; var incr = openValues.Count > 1 ? (openValues.Count - 1).ToString() : ""; var newOpenValue = $"OPEN{incr}"; key.SetValue(newOpenValue, xllToRegister); key.Close(); }
private async Task <StreamlabsChatBotData> GatherStreamlabsChatBotSettings(string filePath) { try { StreamlabsChatBotData data = new StreamlabsChatBotData(); await Task.Run(() => { using (NetOffice.ExcelApi.Application application = new NetOffice.ExcelApi.Application()) { application.DisplayAlerts = false; NetOffice.ExcelApi.Workbook workbook = application.Workbooks.Open(filePath); if (workbook != null) { foreach (NetOffice.ExcelApi.Worksheet worksheet in workbook.Worksheets.AsEnumerable()) { if (worksheet != null) { List <List <string> > dataValues = new List <List <string> >(); int totalColumns = 0; bool hasValue = false; do { hasValue = false; NetOffice.ExcelApi.Range range = worksheet.Cells[1, totalColumns + 1]; if (range.Value != null) { totalColumns++; hasValue = true; } } while (hasValue); int currentRow = 2; List <string> values = new List <string>(); do { values = new List <string>(); for (int i = 1; i <= totalColumns; i++) { NetOffice.ExcelApi.Range range = worksheet.Cells[currentRow, i]; if (range.Value != null) { values.Add(range.Value.ToString()); } else { values.Add(string.Empty); } } if (!values.All(v => string.IsNullOrEmpty(v))) { dataValues.Add(values); } currentRow++; } while (!values.All(v => string.IsNullOrEmpty(v))); if (worksheet.Name.Equals("Commands")) { data.AddCommands(dataValues); } else if (worksheet.Name.Equals("Timers")) { data.AddTimers(dataValues); } else if (worksheet.Name.Equals("Quotes") || worksheet.Name.Equals("Extra Quotes")) { data.AddQuotes(dataValues); } else if (worksheet.Name.Equals("Ranks")) { data.AddRanks(dataValues); } else if (worksheet.Name.Equals("Currency")) { data.AddViewers(dataValues); } else if (worksheet.Name.Equals("Events")) { data.AddEvents(dataValues); } } } } application.Quit(); } }); return(data); } catch (Exception ex) { Logger.Log(ex); } return(null); }
void makeGraph() { // Open Excel API using (var excelApplication = new NetOffice.ExcelApi.Application()) { // Add workbook var workBook = excelApplication.Workbooks.Add(); workBook.Worksheets.Add(); // set worksheet to set data var dataSheet = (NetOffice.ExcelApi.Worksheet)workBook.Worksheets[1]; dataSheet.Name = "Data"; // set worksheet to set chart var chartSheet = (NetOffice.ExcelApi.Worksheet)workBook.Worksheets[2]; chartSheet.Name = "Charts"; // input data progressBar1.Maximum = li.Count; for (int i = 0; i < li.Count; i++) { dataSheet.Cells[1, i + 1].Value = fileName[i]; for (int j = 0; j < li[i].Count; j++) { dataSheet.Cells[j + 2, i + 1].Value = li[i][j]; } var chart = ((NetOffice.ExcelApi.ChartObjects)chartSheet.ChartObjects()).Add(0, 200*i, 350, 200); chart.Chart.ChartType = NetOffice.ExcelApi.Enums.XlChartType.xlLine; chart.Chart.SetSourceData(dataSheet.Range(dataSheet.Cells[1, i + 1], dataSheet.Cells[li[i].Count, i + 1])); progressBar1.PerformStep(); } workBook.SaveAs(sfd()); excelApplication.Quit(); } }