public void RunExample() { // start excel and turn off msg boxes Excel.Application excelApplication = new Excel.Application(); excelApplication.DisplayAlerts = false; // create a utils instance, not need for but helpful to keep the lines of code low CommonUtils utils = new CommonUtils(excelApplication); // add a new workbook //Excel.Workbook workBook = excelApplication.Workbooks.Add(); Excel.Workbook workBook = excelApplication.Workbooks.Open(@"C:\Users\Gilbert Perlaza\Dropbox\HPC\MttoApp\Docs\FORMATO EWO EN BLANCO UNIFICADO OT.XLSX"); Excel.Worksheet workSheet = (Excel.Worksheet)workBook.Worksheets[1]; workSheet.Cells[1, 1].Value = "NetOffice Excel Example 04"; // create a star Excel.Shape starShape = workSheet.Shapes.AddShape(MsoAutoShapeType.msoShape32pointStar, 10, 50, 200, 20); // create a simple textbox Excel.Shape textBox = workSheet.Shapes.AddTextbox(MsoTextOrientation.msoTextOrientationHorizontal, 10, 150, 200, 50); Excel.Shape rb = workSheet.Shapes.AddFormControl(Excel.Enums.XlFormControl.xlOptionButton, 100, 100, 100, 100); var sh = workSheet.Shapes; foreach (var item in sh) { if (item.Name.Equals("Option Button 1")) { item.ControlFormat.Value = 1; } } rb.TextFrame.Characters().Text = "Hola prueba"; rb.ControlFormat.Value = 0; textBox.TextFrame.Characters().Text = "text"; textBox.TextFrame.Characters().Font.Size = 14; // create a wordart Excel.Shape textEffect = workSheet.Shapes.AddTextEffect(MsoPresetTextEffect.msoTextEffect14, "WordArt", "Arial", 12, MsoTriState.msoTrue, MsoTriState.msoFalse, 10, 250); // create text effect Excel.Shape textDiagram = workSheet.Shapes.AddTextEffect(MsoPresetTextEffect.msoTextEffect11, "Effect", "Arial", 14, MsoTriState.msoFalse, MsoTriState.msoFalse, 10, 350); // save the book string workbookFile = utils.File.Combine(HostApplication.RootDirectory, "Example04", DocumentFormat.Normal); workBook.SaveAs(workbookFile); // close excel and dispose reference excelApplication.Quit(); excelApplication.Dispose(); // show end dialog HostApplication.ShowFinishDialog(null, workbookFile); }
public TestResult DoTest() { Excel.Application application = null; DateTime startTime = DateTime.Now; try { // start excel and turn off msg boxes application = COMObject.Create <Excel.Application>(COMObjectCreateOptions.CreateNewCore); application.DisplayAlerts = false; // add a new workbook Excel.Workbook workBook = application.Workbooks.Add(); Excel.Worksheet workSheet = (Excel.Worksheet)workBook.Worksheets[1]; workSheet.Cells[1, 1].Value = "these sample shapes was dynamicly created by code."; // create a star Excel.Shape starShape = workSheet.Shapes.AddShape(MsoAutoShapeType.msoShape32pointStar, 10, 50, 200, 20); // create a simple textbox Excel.Shape textBox = workSheet.Shapes.AddTextbox(MsoTextOrientation.msoTextOrientationHorizontal, 10, 150, 200, 50); textBox.TextFrame.Characters().Text = "text"; textBox.TextFrame.Characters().Font.Size = 14; // create a wordart Excel.Shape textEffect = workSheet.Shapes.AddTextEffect(MsoPresetTextEffect.msoTextEffect14, "WordArt", "Arial", 12, MsoTriState.msoTrue, MsoTriState.msoFalse, 10, 250); // create text effect Excel.Shape textDiagram = workSheet.Shapes.AddTextEffect(MsoPresetTextEffect.msoTextEffect11, "Effect", "Arial", 14, MsoTriState.msoFalse, MsoTriState.msoFalse, 10, 350); return(new TestResult(true, DateTime.Now.Subtract(startTime), "", null, "")); } catch (Exception exception) { return(new TestResult(false, DateTime.Now.Subtract(startTime), exception.Message, exception, "")); } finally { if (null != application) { application.Quit(); application.Dispose(); } } }
public void RunExample() { // start excel and turn off msg boxes Excel.Application excelApplication = new Excel.Application(); excelApplication.DisplayAlerts = false; // create a utils instance, not need for but helpful to keep the lines of code low CommonUtils utils = new CommonUtils(excelApplication); // add a new workbook Excel.Workbook workBook = excelApplication.Workbooks.Add(); Excel.Worksheet workSheet = (Excel.Worksheet)workBook.Worksheets[1]; workSheet.Cells[1, 1].Value = "NetOffice Excel Example 04"; // create a star Excel.Shape starShape = workSheet.Shapes.AddShape(MsoAutoShapeType.msoShape32pointStar, 10, 50, 200, 20); // create a simple textbox Excel.Shape textBox = workSheet.Shapes.AddTextbox(MsoTextOrientation.msoTextOrientationHorizontal, 10, 150, 200, 50); textBox.TextFrame.Characters().Text = "text"; textBox.TextFrame.Characters().Font.Size = 14; // create a wordart Excel.Shape textEffect = workSheet.Shapes.AddTextEffect(MsoPresetTextEffect.msoTextEffect14, "WordArt", "Arial", 12, MsoTriState.msoTrue, MsoTriState.msoFalse, 10, 250); // create text effect Excel.Shape textDiagram = workSheet.Shapes.AddTextEffect(MsoPresetTextEffect.msoTextEffect11, "Effect", "Arial", 14, MsoTriState.msoFalse, MsoTriState.msoFalse, 10, 350); // save the book string workbookFile = utils.File.Combine(HostApplication.RootDirectory, "Example04", DocumentFormat.Normal); workBook.SaveAs(workbookFile); // close excel and dispose reference excelApplication.Quit(); excelApplication.Dispose(); // show end dialog HostApplication.ShowFinishDialog(null, workbookFile); }
public void RunExample() { // start excel and turn off msg boxes Excel.Application excelApplication = new Excel.Application(); excelApplication.DisplayAlerts = false; // add a new workbook Excel.Workbook workBook = excelApplication.Workbooks.Add(); Excel.Worksheet workSheet = (Excel.Worksheet)workBook.Worksheets[1]; workSheet.Cells[1, 1].Value = "these sample shapes was dynamicly created by code."; // create a star Excel.Shape starShape = workSheet.Shapes.AddShape(MsoAutoShapeType.msoShape32pointStar, 10, 50, 200, 20); // create a simple textbox Excel.Shape textBox = workSheet.Shapes.AddTextbox(MsoTextOrientation.msoTextOrientationHorizontal, 10, 150, 200, 50); textBox.TextFrame.Characters().Text = "text"; textBox.TextFrame.Characters().Font.Size = 14; // create a wordart Excel.Shape textEffect = workSheet.Shapes.AddTextEffect(MsoPresetTextEffect.msoTextEffect14, "WordArt", "Arial", 12, MsoTriState.msoTrue, MsoTriState.msoFalse, 10, 250); // create text effect Excel.Shape textDiagram = workSheet.Shapes.AddTextEffect(MsoPresetTextEffect.msoTextEffect11, "Effect", "Arial", 14, MsoTriState.msoFalse, MsoTriState.msoFalse, 10, 350); // save the book string fileExtension = GetDefaultExtension(excelApplication); string workbookFile = string.Format("{0}\\Example04{1}", _hostApplication.RootDirectory, fileExtension); workBook.SaveAs(workbookFile); // close excel and dispose reference excelApplication.Quit(); excelApplication.Dispose(); // show dialog for the user(you!) _hostApplication.ShowFinishDialog(null, workbookFile); }
public virtual void EndConnect(NetOffice.ExcelApi.Shape connectedShape, Int32 connectionSite) { InvokerService.InvokeInternal.ExecuteMethod(this, "EndConnect", connectedShape, connectionSite); }
static void ExportChart(Shape shape, string strFileName) { //shape.Shadow.Visible = MsoTriState.msoFalse; shape.Shadow.Size = 0; shape.Height = shape.Width / _ratioRate; Chart chart = shape.Chart; string strName = chart.ChartTitle.Caption; if (strName.Contains('\r')) { strName = strName.Split('\r')[0]; } int iSeriesCnt = (chart.SeriesCollection() as SeriesCollection).Count; string strChartSaveName = _strOupPutPath; int i = 1; while (true) { strChartSaveName = $"{_strOupPutPath}{strName}.crtx"; if (!File.Exists(strChartSaveName)) { break; } strName += i; i++; } chart.SaveChartTemplate(strChartSaveName); string strBigImg = $"{_strOupPutPath}\\{strName}_1.png"; string strSmallImg = $"{_strOupPutPath}\\m_{strName}_1.png"; shape.Copy(); Object obj = Clipboard.GetData("PNG"); Image imgTemp = new Bitmap((MemoryStream)obj); Clipboard.Clear(); Image imgBig = new Bitmap(imgTemp, 680, 407); Image imgSmall = new Bitmap(imgTemp, 499, 299); imgBig.Save(strBigImg); imgSmall.Save(strSmallImg); imgTemp.Dispose(); imgBig.Dispose(); imgSmall.Dispose(); string strChartType = chart.ChartType.ToString(); var infos = _listInfo.Where(d => d[0] == strChartType); if (!infos.Any()) { throw new Exception($"找不到{strChartType}类型标签"); } else if (infos.Count() != 1) { throw new Exception($"{strChartType}类型标签重复"); } List <string> listLine = new List <string>(); listLine.Add(strName); listLine.Add(_strUserName); listLine.Add(_strUserID); listLine.Add("2"); List <string> listInfo = infos.Single().ToList(); listLine.Add(listInfo[1]); listLine.Add("3"); listInfo.RemoveAt(0); listInfo.RemoveAt(0); listInfo.Insert(0, iSeriesCnt.ToString()); string strTag = string.Join(" ", listInfo); listLine.Add(strTag); listLine.Add(strName + ".crtx"); listLine.Add("999"); File.AppendAllLines(_strInfoFile, new[] { string.Join(",", listLine) }, Encoding.GetEncoding("GB2312")); }
public virtual Int32 EndConnect(NetOffice.ExcelApi.Shape connectedShape, Int32 connectionSite) { return(InvokerService.InvokeInternal.ExecuteInt32MethodGet(this, "EndConnect", connectedShape, connectionSite)); }