Exemplo n.º 1
0
 public static void Initialize(         
  IConsole console,
  ISurface surface,
  IStyle style,
  IDrawings drawing,
  IShapes shapes,
  IImages images,
  IControls controls,
  ISounds sounds,         
  IKeyboard keyboard,
  IMouse mouse,
  ITimer timer,
  IFlickr flickr,
  ISpeech speech,
  CancellationToken token)
 {
     TextWindow.Init(console);
      Desktop.Init(surface);
      GraphicsWindow.Init(style, surface, drawing, keyboard, mouse);
      Shapes.Init(shapes);
      ImageList.Init(images);
      Turtle.Init(surface, drawing, shapes);
      Controls.Init(controls);
      Sound.Init(sounds);
      Timer.Init(timer);
      Stack.Init();
      Flickr.Init(flickr);
      Speech.Init(speech);
      Program.Init(token);
 }
        static void Main(string[] args)
        {
            var quad = new Quad {
            };

            quad.Perimeter(1, 2, 3, 4);

            var rect = new Rectangle {
            };

            rect.Perimeter(2, 4, 6, 8);

            var square = new Square {
            };

            square.Perimeter(3, 5, 7, 9);



            IShapes[] shapes = new IShapes[10];

            shapes[0] = quad;
            shapes[1] = rect;
            shapes[2] = square;

            foreach (var shape in shapes)
            {
                ;
            }
        }
Exemplo n.º 3
0
        static void Main(string[] args)
        {
            var quad1 = new Quadrillateral {
                Side1 = 10, Side2 = 10, Side3 = 10, Side4 = 10
            };
            var rec1 = new Rectangle {
                Side1 = 10, Side2 = 10
            };
            var sq1 = new Square {
                Side1 = 12
            };

            IShapes[] shapes = new IShapes[10];
            shapes[0] = quad1;
            shapes[1] = rec1;
            shapes[2] = sq1;

            foreach (var shape in shapes)
            {
                if (shape == null)
                {
                    continue;
                }
                shape.Perimeter();
            }
        }
Exemplo n.º 4
0
 public static void Initialize(
     IConsole console,
     ISurface surface,
     IStyle style,
     IDrawings drawing,
     IShapes shapes,
     IImages images,
     IControls controls,
     ISounds sounds,
     IKeyboard keyboard,
     IMouse mouse,
     ITimer timer,
     IFlickr flickr,
     ISpeech speech,
     CancellationToken token)
 {
     TextWindow.Init(console);
     Desktop.Init(surface);
     GraphicsWindow.Init(style, surface, drawing, keyboard, mouse);
     Shapes.Init(shapes);
     ImageList.Init(images);
     Turtle.Init(surface, drawing, shapes);
     Controls.Init(controls);
     Sound.Init(sounds);
     Timer.Init(timer);
     Stack.Init();
     Flickr.Init(flickr);
     Speech.Init(speech);
     Program.Init(token);
 }
Exemplo n.º 5
0
        static void Main(string[] args)
        {
            IShapes[] shapes = new IShapes[2];

            shapes[0] = new Circle
            {
                Name   = "Jim",
                Color  = "Blue",
                Radius = 5,
            };

            shapes[1] = new Rectangle
            {
                Name   = "Julie",
                Color  = "Red",
                Length = 5,
                Width  = 5,
            };

            Circle circle = (Circle)shapes[0];

            Console.WriteLine($"The Cicumference and Area of {circle.Name} are {circle.CalculateCircum()} " +
                              $"and {circle.CalculateArea()}");

            Rectangle square = (Rectangle)shapes[1];

            Console.WriteLine($"The Perimeter and Area of {square.Name} are {square.CalculatePerim()} " +
                              $"and {square.CalculateArea()}");
        }
Exemplo n.º 6
0
        public Shapes(IBaseFilter baseFilter)
        {
            Type comType = null;

            comType = Type.GetTypeFromCLSID(Clsid.CLSID_TextOverlay);
            if (comType == null)
            {
                throw new NotImplementedException(@"DirectShow FilterGraph not installed/registered!");
            }

            shapeIface = (IShapes)baseFilter;

            /*
             * shapeIface.AddTextOverlay("Eli Arad is here",
             *                          0,
             *                          10,
             *                                                              10,
             *                         200, 100,
             *                          Color.Red,
             *                          14);
             *
             */
            //shapeIface.AddLine(1, 100, 100, 150, 150, Color.Red, 4);
            //shapeIface.Remove(1);
        }
Exemplo n.º 7
0
        private static void shuldNotChangeWidth1(IShapes shape)
        {
            int beforeChange = 10;

            shape.SetHight(20);
            int afterChange = shape.GetWidth();

            Console.WriteLine(beforeChange == afterChange);
        }
Exemplo n.º 8
0
 internal static void Init(ISurface surface, IDrawings drawings, IShapes shapes)
 {
     _graphics  = drawings;
     _shapes    = shapes;
     X          = surface.Width / 2.0;
     Y          = surface.Height / 2.0;
     Angle      = 0;
     _isPenDown = true;
     Hide();
 }
Exemplo n.º 9
0
 public Form1()
 {
     InitializeComponent();
     ListOfShapes  = new Shapes();
     _iShapes      = ListOfShapes;
     _lastPosition = new Point(0, 0);
     shapeNum      = 0;
     onPaint       = false;
     neuralNetwork = new NeuralNetwork();
 }
Exemplo n.º 10
0
        public void ShapeDescription(IShapes shape)
        {
            if (shape == null)
            {
                Console.WriteLine("Undefined Shape");
            }

            if (shape != null)
            {
                Console.WriteLine(shape.ShapeName + " has " + shape.SidesOfShape.ToString() + " sides.");
            }
        }
Exemplo n.º 11
0
        private void editToolStripMenuItem_Click(object sender, EventArgs e)
        {
            EditShapes form = new EditShapes();

            foreach (var it in listShape)
            {
                form.listBox1.Items.Add(it.Name.ToString());
            }
            form.ShowDialog();
            if (form.listBox1.SelectedIndex != -1 && form.listBox2.SelectedIndex != -1)
            {
                isSave = false;
                shape  = listShape.FirstOrDefault(p => p.Name == form.listBox1.GetItemText(form.listBox1.SelectedItem));
                listShape.Remove(shape);
                if (form.listBox2.SelectedIndex == 0)
                {
                    ColorDialog colorDialog = new ColorDialog();
                    if (colorDialog.ShowDialog() == DialogResult.OK)
                    {
                        shape.Color = colorDialog.Color;
                        listShape.Add(shape);
                        shape = null;
                        listShapes.ClearSelected();
                        listColor.ClearSelected();
                        panel1.Refresh();
                        foreach (var it in listShape)
                        {
                            grap.FillPolygon(new SolidBrush(it.Color), it.ToArray());
                        }
                    }
                }
                else if (form.listBox2.SelectedIndex == 1)
                {
                    isShapes = true;
                    MessageBox.Show("Please select new position");
                }
                else if (form.listBox2.SelectedIndex == 2)
                {
                    listShapes.ClearSelected();
                    listColor.ClearSelected();
                    panel1.Refresh();
                    foreach (var it in listShape)
                    {
                        grap.FillPolygon(new SolidBrush(it.Color), it.ToArray());
                    }
                }
            }
        }
Exemplo n.º 12
0
        public static IShapes MoveToPoint(IShapes shape, Point newCenter)
        {
            Point previouseCenter = shape.Center();
            int   xShifting       = previouseCenter.X - newCenter.X;
            int   yShifting       = previouseCenter.Y - newCenter.Y;

            var points = shape.ToArray();

            for (int i = 0; i < points.Count(); i++)
            {
                points[i].X -= xShifting;
                points[i].Y -= yShifting;
            }
            shape.Points = points.ToList();

            return(shape);
        }
Exemplo n.º 13
0
        /// <summary>
        /// Recursion for process
        /// </summary>
        public void Process()
        {
            Console.WriteLine("Enter Shape Name: ");

            IShapes shape = shapeFactory.CreateShape(Console.ReadLine());

            if (shape != null)
            {
                container.Add(shape);
            }

            messenger.ShapeDescription(shape);
            messenger.SumOfSides(container.Sum(x => x.SidesOfShape));

            Console.WriteLine("Do you want to do it again?(Y/N)");

            if (Console.ReadLine() == "Y")
            {
                Console.Clear();
                Process();
            }
        }
Exemplo n.º 14
0
 private void panel1_MouseClick(object sender, MouseEventArgs e)
 {
     if (e.Button == MouseButtons.Left)
     {
         pointX = e.X;
         pointY = e.Y;
         panel_Paint(this, null);
     }
     else if (e.Button == MouseButtons.Right)
     {
         if (isShapes)
         {
             listShape.Remove(shape);
             shape = ShapesBL.MoveToPoint(shape, new Point(e.X, e.Y));
             listShape.Add(shape);
             shape    = null;
             isShapes = false;
             listShapes.ClearSelected();
             listColor.ClearSelected();
             panel1.Refresh();
             foreach (var it in listShape)
             {
                 grap.FillPolygon(new SolidBrush(it.Color), it.ToArray());
             }
             isSave = false;
         }
         else
         {
             shape = listShape.FirstOrDefault(p => Geometry.IsInPolygon(p.ToArray(), new Point(e.X, e.Y)) == true);
             if (shape != null)
             {
                 isShapes = true;
                 MessageBox.Show("Please select new position");
             }
         }
     }
 }
Exemplo n.º 15
0
        /// <summary>
        /// Insert a file into an already created workbook
        /// </summary>
        /// <param name="workbook"></param>
        /// <param name="tmpFile"></param>
        /// <param name="imageSize"></param>
        private static void InsertIntoExistingWorkbook(IWorkbook workbook, string tmpFile, Size imageSize)
        {
            IWorksheet workSheet = workbook.ActiveSheet;

            if (workSheet == null)
            {
                return;
            }
            using (IShapes shapes = workSheet.Shapes) {
                if (shapes != null)
                {
                    using (IShape shape = shapes.AddPicture(tmpFile, MsoTriState.msoFalse, MsoTriState.msoTrue, 0, 0, imageSize.Width, imageSize.Height)) {
                        if (shape != null)
                        {
                            shape.Top             = 40;
                            shape.Left            = 40;
                            shape.LockAspectRatio = MsoTriState.msoTrue;
                            shape.ScaleHeight(1, MsoTriState.msoTrue, MsoScaleFrom.msoScaleFromTopLeft);
                            shape.ScaleWidth(1, MsoTriState.msoTrue, MsoScaleFrom.msoScaleFromTopLeft);
                        }
                    }
                }
            }
        }
Exemplo n.º 16
0
        //
        // GET: /EncryptAndDecrypt/
        public ActionResult GroupShapes(string button, string Group1)
        {
            string basePath = _hostingEnvironment.WebRootPath;

            if (button == null)
            {
                return(View());
            }

            else if (button == "Input Document")
            {
                //New instance of XlsIO is created.[Equivalent to launching Microsoft Excel with no workbooks open].
                //The instantiation process consists of two steps.

                //Step 1 : Instantiate the spreadsheet creation engine.
                ExcelEngine excelEngine = new ExcelEngine();

                //Step 2 : Instantiate the excel application object.
                IApplication application = excelEngine.Excel;
                application.DefaultVersion = ExcelVersion.Excel2016;

                FileStream inputStream = new FileStream(basePath + @"/XlsIO/GroupShapes.xlsx", FileMode.Open, FileAccess.Read);

                // Opening the Existing Worksheet from a Workbook.
                IWorkbook workbook = application.Workbooks.Open(inputStream);

                try
                {
                    workbook.Version = ExcelVersion.Excel2013;
                    string ContentType = "Application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
                    string fileName    = "GroupShapes.xlsx";

                    MemoryStream ms = new MemoryStream();
                    workbook.SaveAs(ms);
                    ms.Position = 0;

                    return(File(ms, ContentType, fileName));
                }
                catch (Exception)
                {
                }

                // Close the workbook
                workbook.Close();
                excelEngine.Dispose();
            }
            else
            {
                //New instance of XlsIO is created.[Equivalent to launching Microsoft Excel with no workbooks open].
                //The instantiation process consists of two steps.

                //Step 1 : Instantiate the spreadsheet creation engine.
                ExcelEngine excelEngine = new ExcelEngine();

                //Step 2 : Instantiate the excel application object.
                IApplication application = excelEngine.Excel;
                application.DefaultVersion = ExcelVersion.Excel2016;

                FileStream inputStream = new FileStream(basePath + @"/XlsIO/GroupShapes.xlsx", FileMode.Open, FileAccess.Read);
                // Opening the encrypted Workbook.
                IWorkbook workbook = application.Workbooks.Open(inputStream, ExcelParseOptions.Default, true, "PASSWORD");

                IWorksheet worksheet;

                if (Group1 == "Group")
                {
                    // The first worksheet object in the worksheets collection is accessed.
                    worksheet = workbook.Worksheets[0];
                    IShapes shapes = worksheet.Shapes;

                    IShape[] groupItems;
                    for (int i = 0; i < shapes.Count; i++)
                    {
                        if (shapes[i].Name == "Development" || shapes[i].Name == "Production" || shapes[i].Name == "Sales")
                        {
                            groupItems = new IShape[] { shapes[i], shapes[i + 1], shapes[i + 2], shapes[i + 3], shapes[i + 4], shapes[i + 5] };
                            shapes.Group(groupItems);
                            i = -1;
                        }
                    }

                    groupItems = new IShape[] { shapes[0], shapes[1], shapes[2], shapes[3], shapes[4], shapes[5], shapes[6] };

                    // Group the selected shapes
                    shapes.Group(groupItems);
                }
                else if (Group1 == "UngroupAll")
                {
                    // The second worksheet object in the worksheets collection is accessed.
                    worksheet = workbook.Worksheets[1];
                    IShapes shapes = worksheet.Shapes;

                    // Ungroup group shape and its all the inner shapes.
                    shapes.Ungroup(shapes[0] as IGroupShape, true);
                    worksheet.Activate();
                }
                else if (Group1 == "Ungroup")
                {
                    // The second worksheet object in the worksheets collection is accessed.
                    worksheet = workbook.Worksheets[1];
                    IShapes shapes = worksheet.Shapes;

                    // Ungroup group shape.
                    shapes.Ungroup(shapes[0] as IGroupShape);
                    worksheet.Activate();
                }

                try
                {
                    workbook.Version = ExcelVersion.Excel2013;
                    string ContentType = "Application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
                    string fileName    = "GroupShapes.xlsx";

                    MemoryStream ms = new MemoryStream();
                    workbook.SaveAs(ms);
                    ms.Position = 0;

                    return(File(ms, ContentType, fileName));
                }
                catch
                {
                }

                // Close the workbook
                workbook.Close();
                excelEngine.Dispose();
            }
            return(View());
        }
Exemplo n.º 17
0
        /// <summary>
        /// This is the method where user can type "run","clear" and "reset " command to execute, clear and reset commandline simulteneouly.
        /// </summary>
        /// <param name="sender">Reference to the control object</param>
        /// <param name="e">event data</param>
        private void executeInput_TextChanged(object sender, EventArgs e)
        {
            if (executeInput.Text.ToLower().Trim() == "run")
            {
                g = ShapeOutput.CreateGraphics();
                string   command     = ProgramInput.Text.ToLower();
                string[] commandline = command.Split(new String[] { "\n" },
                                                     StringSplitOptions.RemoveEmptyEntries);

                for (int k = 0; k < commandline.Length; k++)
                {
                    string[] cmd = commandline[k].Split(' ');

                    if (cmd[0].Equals("moveto") == true)
                    {
                        ShapeOutput.Refresh();
                        string[] param = cmd[1].Split(',');

                        if (param.Length != 2)
                        {
                            MessageBox.Show("Please Input Valid Parameter!!!");
                        }
                        else
                        {
                            Int32.TryParse(param[0], out x);
                            Int32.TryParse(param[1], out y);
                            MoveTo(x, y);
                        }
                    }
                    else if (cmd[0].Equals("drawto") == true)
                    {
                        string[] param = cmd[1].Split(',');
                        int      x = 0, y = 0;
                        if (param.Length != 2)
                        {
                            MessageBox.Show("Please Input Valid Parameter!!!");
                        }
                        else
                        {
                            Int32.TryParse(param[0], out x);
                            Int32.TryParse(param[1], out y);
                            DrawTo(x, y);
                        }
                    }
                    else if (cmd[0].Equals("rectangle") == true)
                    {
                        if (cmd.Length < 2)
                        {
                            MessageBox.Show("Please Input Valid Parameter!!!");
                        }
                        else
                        {
                            string[] param = cmd[1].Split(',');
                            if (param.Length < 2)
                            {
                                MessageBox.Show("Please Input Valid Parameter!!!");
                            }
                            else
                            {
                                Int32.TryParse(param[0], out width);
                                Int32.TryParse(param[1], out height);
                                IShapes   rectangle = factory.getShape("rectangle");
                                Rectangle r         = new Rectangle();
                                r.set(Color.Black, x, y, width, height);
                                r.Draw(g);
                            }
                        }
                    }

                    else if (cmd[0].Equals("circle") == true)
                    {
                        if (cmd.Length != 2)
                        {
                            MessageBox.Show("Please Input Valid Parameter!!!");
                        }
                        else
                        {
                            if (cmd[1].Equals("radius") == true)
                            {
                                IShapes circle = factory.getShape("circle");
                                Circle  c      = new Circle();
                                c.set(Color.AliceBlue, x, y, radius);
                                c.Draw(g);
                            }
                            else
                            {
                                Int32.TryParse(cmd[1], out radius);
                                IShapes circle = factory.getShape("circle");
                                Circle  c      = new Circle();
                                c.set(Color.AliceBlue, x, y, radius);
                                c.Draw(g);
                            }
                        }
                    }

                    else if (cmd[0].Equals("triangle") == true)
                    {
                        string[] param = cmd[1].Split(',');
                        if (param.Length != 2)
                        {
                            MessageBox.Show("Please Input Valid Parameter!!!");
                        }
                        else
                        {
                            Int32.TryParse(param[0], out width);
                            Int32.TryParse(param[1], out height);
                            IShapes  triangle = factory.getShape("triangle");
                            Triangle r        = new Triangle();
                            r.set(Color.AliceBlue, x, y, width, height);
                            r.Draw(g);
                        }
                    }
                    else if (cmd[0].Equals("filltriangle") == true)
                    {
                        string[] param = cmd[1].Split(',');
                        if (param.Length != 2)
                        {
                            MessageBox.Show("Please Input Valid Parameter!!!");
                        }
                        else
                        {
                            Int32.TryParse(param[0], out width);
                            Int32.TryParse(param[1], out height);
                            IShapes  circle = factory.getShape("filltriangle");
                            Triangle r      = new Triangle();
                            r.set(Color.AliceBlue, x, y, width, height);
                            r.draw(g);
                        }
                    }
                    else if (cmd[0].Equals("pen") == true)
                    {
                        if (cmd[1] == "red")//if red then color changes to red
                        {
                            c = Color.Red;
                        }
                        else if (cmd[1] == "blue")//if blue then color changes to blue
                        {
                            c = Color.Blue;
                        }
                        else if (cmd[1] == "yellow")//if yellow then color changes to yellow
                        {
                            c = Color.Yellow;
                        }
                        else
                        {
                            c = Color.AliceBlue;//default color
                        }
                    }
                    else if (cmd[0].Equals("fillrectangle") == true)
                    {
                        if (cmd.Length < 2)
                        {
                            MessageBox.Show("Please Input Valid Parameter!!!");
                        }
                        else
                        {
                            string[] param = cmd[1].Split(',');
                            if (param.Length < 2)
                            {
                                MessageBox.Show("Please Input Valid Parameter!!!");
                            }
                            else
                            {
                                Int32.TryParse(param[0], out width);
                                Int32.TryParse(param[1], out height);
                                IShapes   rectangle = factory.getShape("fillrectangle");
                                Rectangle r         = new Rectangle();
                                r.set(Color.Black, x, y, width, height);
                                r.draw(g);
                            }
                        }
                    }
                    else if (cmd[0].Equals("fillcircle") == true)
                    {
                        if (cmd.Length != 2)
                        {
                            MessageBox.Show("Please Input Valid Parameter!!!");
                        }
                        else
                        {
                            if (cmd[1].Equals("radius") == true)
                            {
                                IShapes circle = factory.getShape("fillcircle");
                                Circle  c      = new Circle();
                                c.set(Color.AliceBlue, x, y, radius);
                                c.draw(g);
                            }
                            else
                            {
                                Int32.TryParse(cmd[1], out radius);
                                IShapes circle = factory.getShape("fillcircle");
                                Circle  c      = new Circle();
                                c.set(Color.AliceBlue, x, y, radius);
                                c.draw(g);
                            }
                        }
                    }

                    else if (!cmd[0].Equals(null))
                    {
                        int errorLine = k + 1;
                        MessageBox.Show("Invalid command recognised on line " + errorLine, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }
            else if (executeInput.Text.ToLower().Trim() == "clear")
            {
                ShapeOutput.Invalidate();
            }
            else if (executeInput.Text.ToLower().Trim() == "reset")
            {
                ProgramInput.Clear();
                MultilineProgramInput.Clear();
                ShapeOutput.Invalidate();

                size1       = 0;
                size2       = 0;
                xlabel.Text = size1.ToString();
                ylabel.Text = size2.ToString();
            }
        }
Exemplo n.º 18
0
        private void GenerateContourMap()
        {
            Surfer.Application app    = new Surfer.Application();
            IDocuments         docs   = app.Documents;
            IPlotDocument      Doc    = (IPlotDocument)docs.Add(SrfDocTypes.srfDocPlot); //創建一個空白繪圖文檔
            IShapes            Shapes = Doc.Shapes;

            #region 添加等值面
            IMapFrame contourMapFrame = Shapes.AddContourMap(path + "temp.grd");        //加載網格文件
            for (int i = 1; i <= contourMapFrame.Axes.Count; i++)
            {
                contourMapFrame.Axes.Item(i).Visible       = false;
                contourMapFrame.Axes.Item(i).MajorTickType = SrfTickType.srfTickNone;
                contourMapFrame.Axes.Item(i).ShowLabels    = false;
            }
            contourMapFrame.SetLimits(xMin: 140000,     //x最小值
                                      xMax: 370000,     //x最大者
                                      yMin: 2400000,    //y最小值
                                      yMax: 2800000     //y最大值
                                      );
            contourMapFrame.xMapPerPU = 23000;          //設置比例
            contourMapFrame.yMapPerPU = 20000;          //設置比例


            IContourMap contourMap = (IContourMap)contourMapFrame.Overlays.Item(1);

            /*
             * contourMap.ShowColorScale = true;										// 顯示對應色柱
             * contourMap.ColorScale.Top = 10;										//色柱y方向位置
             * contourMap.ColorScale.Left = contourMap.Left + contourMap.Width + 0.8;//色柱x方向位置
             * contourMap.ColorScale.Width = 1;									//色柱寬度
             * contourMap.ColorScale.Height = 10;										//色柱高度
             * contourMap.ColorScale.LabelFont.Size = 10;
             * contourMap.ColorScale.LabelFont.Face = "Time New Roman";
             * contourMap.ColorScale.LabelFrequency = 1;
             * contourMap.ColorScale.Name = "PM2.5 (μg/m3)";
             */

            contourMap.FillContours = true;    //添加顏色填充
            //通過文件加載顏色
            ILevels levels = contourMap.Levels;
            levels.LoadFile(path + "PM25.lvl");

            //加載系統顏色
            //contourMap.FillForegroundColorMap.LoadFile(path + "Rainbow.clr");
            //contourMap.ApplyFillToLevels(1, 1, 0);

            //使用灰色
            //contourMap.Levels.AutoGenerate(contourMap.Grid.zMin,contourMap.Grid.zMax,10);

            for (int i = 0; i < contourMap.Levels.Count; i++)
            {
                contourMap.Levels.Item(i + 1).ShowLabel  = false;                               //顯示等值線上的數值
                contourMap.Levels.Item(i + 1).ShowHach   = false;                               //
                contourMap.Levels.Item(i + 1).Line.Style = "Invisible";                         //不顯示線
            }

            contourMap.SmoothContours = SrfConSmoothType.srfConSmoothNone;       //平滑等值線邊界當前設置不平滑
            #endregion


            #region 添加邊界
            //後添加的會覆蓋在先前添加的圖片之上
            IMapFrame boundryMapFrame = Shapes.AddBaseMap(path + "city.shp", "Defaults=1");
            for (int i = 1; i <= boundryMapFrame.Axes.Count; i++)
            {
                boundryMapFrame.Axes.Item(i).Visible       = false;                   //隱藏軸線
                boundryMapFrame.Axes.Item(i).MajorTickType = SrfTickType.srfTickNone; //隱藏邊線
                boundryMapFrame.Axes.Item(i).ShowLabels    = false;                   //隱藏軸線上的坐標
            }
            boundryMapFrame.SetLimits(xMin: 140000,                                   //x最小值
                                      xMax: 370000,                                   //x最大者
                                      yMin: 2400000,                                  //y最小值
                                      yMax: 2800000                                   //y最大值
                                      );
            boundryMapFrame.xMapPerPU = 23000;
            boundryMapFrame.yMapPerPU = 20000;

            IBaseMap boundryBaseMap = (IBaseMap)boundryMapFrame.Overlays.Item(1);
            boundryBaseMap.Line.Width = 0.001;                          //設置邊線寬度
            #endregion

            string strWH = string.Format("width = {0:f0}, height = {1:f0}, KeepAspect = 1, ColorDepth = 32", 680, 1280); //設置輸出圖片的高度和寬度
            Doc.Export2(path + "Image.png", SelectionOnly: false, Options: strWH, FilterId: "png");                      //設置輸出圖片格式名
            Doc.Close(SrfSaveTypes.srfSaveChangesNo);                                                                    //不生成srf文件
            app.Quit();
            System.GC.Collect(System.GC.GetGeneration(app));
        }
Exemplo n.º 19
0
 private static void Display(IShapes shape)
 {
     Console.WriteLine("Area :" + shape.AreaCalaculation());
 }
Exemplo n.º 20
0
        private void txt_Execution_Box_TextChanged(object sender, EventArgs e)
        {
            if (txt_Execution_instruction.Text.ToLower().Trim() == "run")
            {
                Graphics g           = Output_Box.CreateGraphics();
                string   command     = txt_cmd_shp.Text.ToLower();
                string[] commandline = command.Split(new String[] { "\n" },
                                                     StringSplitOptions.RemoveEmptyEntries);

                for (int k = 0; k < commandline.Length; k++)
                {
                    string[] cmd = commandline[k].Split(' ');
                    if (cmd[0].Equals("moveto") == true)
                    {
                        Output_Box.Refresh();
                        string[] param = cmd[1].Split(',');
                        if (param.Length != 2)
                        {
                            MessageBox.Show("The Parameter that you have inputted is not correct.");
                        }
                        else
                        {
                            Int32.TryParse(param[0], out x);
                            Int32.TryParse(param[1], out y);
                            moveTo(x, y);
                        }
                    }
                    else if (cmd[0].Equals("drawto") == true)
                    {
                        string[] param = cmd[1].Split(',');
                        int      x = 0, y = 0;
                        if (param.Length != 2)
                        {
                            MessageBox.Show("The Parameter that you have inputted is not correct.");
                        }
                        else
                        {
                            Int32.TryParse(param[0], out x);
                            Int32.TryParse(param[1], out y);
                            drawTo(x, y);
                        }
                    }
                    else if (cmd[0].Equals("rectangle") == true)
                    {
                        if (cmd.Length < 2)
                        {
                            MessageBox.Show("Please input your parameter correctly !!! ");
                        }
                        else
                        {
                            string[] param = cmd[1].Split(',');
                            if (param.Length < 2)
                            {
                                MessageBox.Show("Please input your parameter correctly !!! ");
                            }
                            else
                            {
                                Int32.TryParse(param[0], out width);
                                Int32.TryParse(param[1], out height);
                                IShapes   circle = factory.getShape("rectangle");
                                Rectangle r      = new Rectangle();
                                r.set(Color.Black, x, y, width, height);
                                r.draw(g);
                            }
                        }
                    }

                    else if (cmd[0].Equals("circle") == true)
                    {
                        if (cmd.Length != 2)
                        {
                            MessageBox.Show("The Parameter that you have inputted is not correct.");
                        }
                        else
                        {
                            if (cmd[1].Equals("radius") == true)
                            {
                                IShapes circle = factory.getShape("circle");
                                Circle  c      = new Circle();
                                c.set(Color.Black, x, y, radius);
                                c.draw(g);
                            }
                            else
                            {
                                Int32.TryParse(cmd[1], out radius);
                                IShapes circle = factory.getShape("circle");
                                Circle  c      = new Circle();
                                c.set(Color.Black, x, y, radius);
                                c.draw(g);
                            }
                        }
                    }

                    else if (cmd[0].Equals("triangle") == true)
                    {
                        string[] param = cmd[1].Split(',');
                        if (param.Length != 2)
                        {
                            MessageBox.Show("The Parameter that you have inputted is not correct.");
                        }
                        else
                        {
                            Int32.TryParse(param[0], out width);
                            Int32.TryParse(param[1], out height);
                            IShapes  circle = factory.getShape("triangle");
                            Triangle r      = new Triangle();
                            r.set(Color.Black, x, y, width, height);
                            r.draw(g);
                        }
                    }

                    else if (!cmd[0].Equals(null))
                    {
                        int errorLine = k + 1;
                        MessageBox.Show("Your command is not correct at line " + errorLine, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }
            else
            {
                if (txt_Execution_instruction.Text.ToLower().Trim() == "clear")
                {
                    txt_cmd_shp.Clear();
                }
            }
        }
        /// <summary>
        /// Group or Ungroup the shapes in Excel document
        /// </summary>
        /// <returns>Return the created excel document as stream</returns>
        public MemoryStream GroupShapesXlsIO(string button, string option)
        {
            if (button == "Input Document")
            {
                //New instance of XlsIO is created.[Equivalent to launching Microsoft Excel with no workbooks open].
                //The instantiation process consists of two steps.

                //Step 1 : Instantiate the spreadsheet creation engine
                using (ExcelEngine excelEngine = new ExcelEngine())
                {
                    //Step 2 : Instantiate the excel application object
                    IApplication application = excelEngine.Excel;
                    application.DefaultVersion = ExcelVersion.Excel2016;

                    //Opening the encrypted Workbook
                    FileStream inputStream = new FileStream(ResolveApplicationPath("GroupShapes.xlsx"), FileMode.Open, FileAccess.Read);
                    IWorkbook  workbook    = application.Workbooks.Open(inputStream, ExcelParseOptions.Default, true, "PASSWORD");

                    //Save the document as a stream and retrun the stream
                    using (MemoryStream stream = new MemoryStream())
                    {
                        //Save the created Excel document to MemoryStream
                        workbook.SaveAs(stream);
                        return(stream);
                    }
                }
            }
            else
            {
                //New instance of XlsIO is created.[Equivalent to launching Microsoft Excel with no workbooks open].
                //The instantiation process consists of two steps.

                //Step 1 : Instantiate the spreadsheet creation engine
                using (ExcelEngine excelEngine = new ExcelEngine())
                {
                    //Step 2 : Instantiate the excel application object
                    IApplication application = excelEngine.Excel;
                    application.DefaultVersion = ExcelVersion.Excel2016;

                    //Opening the encrypted Workbook
                    FileStream inputStream = new FileStream(ResolveApplicationPath("GroupShapes.xlsx"), FileMode.Open, FileAccess.Read);
                    IWorkbook  workbook    = application.Workbooks.Open(inputStream, ExcelParseOptions.Default, true, "PASSWORD");

                    IWorksheet worksheet;

                    if (option == "Group")
                    {
                        //The first worksheet object in the worksheets collection is accessed
                        worksheet = workbook.Worksheets[0];
                        IShapes shapes = worksheet.Shapes;

                        IShape[] groupItems;
                        for (int i = 0; i < shapes.Count; i++)
                        {
                            if (shapes[i].Name == "Development" || shapes[i].Name == "Production" || shapes[i].Name == "Sales")
                            {
                                groupItems = new IShape[] { shapes[i], shapes[i + 1], shapes[i + 2], shapes[i + 3], shapes[i + 4], shapes[i + 5] };
                                shapes.Group(groupItems);
                                i = -1;
                            }
                        }

                        groupItems = new IShape[] { shapes[0], shapes[1], shapes[2], shapes[3], shapes[4], shapes[5], shapes[6] };

                        //Group the selected shapes
                        shapes.Group(groupItems);
                    }
                    else if (option == "Ungroup All")
                    {
                        //The second worksheet object in the worksheets collection is accessed
                        worksheet = workbook.Worksheets[1];
                        IShapes shapes = worksheet.Shapes;

                        //Ungroup group shape and its all the inner shapes
                        shapes.Ungroup(shapes[0] as IGroupShape, true);
                        worksheet.Activate();
                    }
                    else if (option == "Ungroup")
                    {
                        //The second worksheet object in the worksheets collection is accessed
                        worksheet = workbook.Worksheets[1];
                        IShapes shapes = worksheet.Shapes;

                        //Ungroup group shape
                        shapes.Ungroup(shapes[0] as IGroupShape);
                        worksheet.Activate();
                    }
                    //Save the document as a stream and retrun the stream
                    using (MemoryStream stream = new MemoryStream())
                    {
                        //Save the created Excel document to MemoryStream
                        workbook.SaveAs(stream);
                        return(stream);
                    }
                }
            }
        }
Exemplo n.º 22
0
 internal static void Init(IShapes shapes)
 {
     _shapes = shapes;
 }
Exemplo n.º 23
0
 internal static void Init(IShapes shapes)
 {
     _shapes = shapes;
 }
Exemplo n.º 24
0
        public SpreadsheetGear.IWorkbook DrawChart(List <ChartModel> columns, List <DataTable> allitem, string sheetname,
                                                   bool OpenSheet = false, bool cellText = false, int cellInt = 0)
        {
            //创建新的workbook
            SpreadsheetGear.IWorkbook   workbook   = Factory.GetWorkbook();
            SpreadsheetGear.IWorksheets worksheets = workbook.Worksheets;
            IWorksheet worksheet = worksheets[0];

            worksheet.Name = sheetname + 1;
            IWorksheetWindowInfo windowInfo = worksheet.WindowInfo;
            IShapes shapes = worksheet.Shapes;

            int    high    = 1;
            int    Rowhigh = 17;
            double top     = 0.5;
            double bottom  = 15.5;

            for (int a = 0; a < columns.Count; a++)
            {
                int row    = 0;
                int column = 0;
                int piecol = 0;

                string site = null;


                if (columns[a].series.Count > 0)
                {
                    row    = columns[a].xAxis.Count;
                    column = columns[a].series.Count;
                }
                if (columns[a].pieseries.Count > 0)
                {
                    piecol = columns[a].pieseries.Count;
                }
                //+((17 + row) * j);

                string[,] arrayChart = null;
                if ((columns[a].charttype.ToString()) == "Pie")
                {
                    site       = "A" + Rowhigh + ":B" + (piecol + Rowhigh);
                    arrayChart = new string[piecol + 1, 2];
                    for (int j = 0; j < (piecol + 1); j++)
                    {
                        if (j == 0)
                        {
                            if (!string.IsNullOrEmpty(columns[a].title))
                            {
                                arrayChart[0, 0] = "";
                                arrayChart[0, 1] = columns[a].title;
                            }
                            else
                            {
                                arrayChart[0, 0] = "";
                                arrayChart[0, 1] = "";
                            }
                        }
                        else
                        {
                            for (int i = 0; i < 2; i++)
                            {
                                if (i == 0)
                                {
                                    arrayChart[j, i] = columns[a].pieseries[j - 1].name;
                                }
                                else
                                {
                                    arrayChart[j, i] = columns[a].pieseries[j - 1].y.ToString();
                                }
                            }
                        }
                    }
                }
                else if ((columns[a].charttype.ToString()) == "Radar")
                {
                    if (row < 3)
                    {
                        row = 3;
                    }
                    string aaa = column / 26 == 0 ? ((char)((65 + column))).ToString() : "" + (char)((64 + column / 26)) + (char)((65 + column % 26));
                    site = "A" + Rowhigh + ":" + aaa + (row + Rowhigh);
                    if (column > 25)
                    {
                        arrayChart = new string[(row + 1), (column + 1)];
                    }
                    for (int j = 0; j < row + 1; j++)
                    {
                        if (j == 0)
                        {
                            for (int i = 0; i < column + 1; i++)
                            {
                                if (i == 0)
                                {
                                    arrayChart[j, i] = "";
                                }
                                else
                                {
                                    arrayChart[j, i] = columns[a].series[i - 1].name;
                                }
                            }
                        }
                        else
                        {
                            for (int k = 0; k < column + 1; k++)
                            {
                                if (k == 0)
                                {
                                    if (j > columns[a].xAxis.Count)
                                    {
                                        arrayChart[j, k] = "";
                                    }
                                    else
                                    {
                                        arrayChart[j, k] = columns[a].xAxis[j - 1];
                                    }
                                }
                                else
                                {
                                    if (j > columns[a].xAxis.Count)
                                    {
                                        arrayChart[j, k] = "";
                                    }
                                    else
                                    {
                                        List <double> adata = columns[a].series[k - 1].data;
                                        arrayChart[j, k] = adata[j - 1].ToString();
                                    }
                                }
                            }
                        }
                    }
                }
                else
                {
                    string aaa = column / 26 == 0 ? ((char)((65 + column))).ToString() : "" + (char)((64 + column / 26)) + (char)((65 + column % 26));
                    site       = "A" + Rowhigh + ":" + aaa + (row + Rowhigh);
                    arrayChart = new string[(row + 1), (column + 1)];
                    for (int j = 0; j < row + 1; j++)
                    {
                        if (j == 0)
                        {
                            for (int i = 0; i < column + 1; i++)
                            {
                                if (i == 0)
                                {
                                    arrayChart[j, i] = "";
                                }
                                else
                                {
                                    arrayChart[j, i] = columns[a].series[i - 1].name;
                                }
                            }
                        }
                        else
                        {
                            for (int k = 0; k < column + 1; k++)
                            {
                                if (k == 0)
                                {
                                    arrayChart[j, k] = columns[a].xAxis[j - 1];
                                }
                                else
                                {
                                    List <double> adata = columns[a].series[k - 1].data;
                                    arrayChart[j, k] = adata[j - 1].ToString();
                                }
                            }
                        }
                    }
                }

                double chartleft   = windowInfo.ColumnToPoints(0.15);
                double charttop    = windowInfo.RowToPoints(top);
                double chartright  = windowInfo.ColumnToPoints(7.85);
                double chartbottom = windowInfo.RowToPoints(bottom);

                SpreadsheetGear.Charts.IChart chart =
                    shapes.AddChart(chartleft, charttop, chartright - chartleft, chartbottom - charttop).Chart;
                IRange source = worksheet.Cells[site];
                source.Value = arrayChart;
                chart.SetSourceData(source, RowCol.Columns);

                if ((columns[a].charttype.ToString()) == "Column")
                {
                    chart.ChartType = ChartType.ColumnClustered;
                }
                else if ((columns[a].charttype.ToString()) == "Line")
                {
                    chart.ChartType = ChartType.Line;
                }
                else if ((columns[a].charttype.ToString()) == "Pie")
                {
                    chart.ChartType = ChartType.Pie;
                    ISeries seriesTotal = chart.SeriesCollection[0];

                    seriesTotal.HasDataLabels             = true;
                    seriesTotal.DataLabels.ShowPercentage = true;
                    seriesTotal.DataLabels.ShowValue      = false;
                }
                else if ((columns[a].charttype.ToString()) == "Radar")
                {
                    chart.ChartType = ChartType.Radar;
                }
                else if ((columns[a].charttype.ToString()) == "Bar")
                {
                    chart.ChartType = ChartType.BarClustered;
                }
                else if ((columns[a].charttype.ToString()) == "BarStacked")
                {
                    chart.ChartType = ChartType.BarStacked;
                }

                if (!string.IsNullOrEmpty(columns[a].title))
                {
                    chart.HasTitle             = true;
                    chart.ChartTitle.Text      = columns[a].title;
                    chart.ChartTitle.Font.Size = 12;
                }

                if ((columns[a].charttype.ToString()) == "Pie")
                {
                    Rowhigh += 17 + piecol;
                    top     += 17 + piecol;
                    bottom  += 17 + piecol;
                    high    += 17 + piecol;
                }
                else
                {
                    Rowhigh += 17 + row;
                    top     += 17 + row;
                    bottom  += 17 + row;
                    high    += 17 + row;
                }
            }
            //数据列表处理
            if (allitem.Count > 0)
            {
                if (OpenSheet)
                {
                    for (int c = 0; c < allitem.Count; c++)
                    {
                        if (columns.Count > 0)
                        {
                            worksheets.Add();
                            worksheet      = worksheets[worksheets.Count - 1];
                            worksheet.Name = sheetname + worksheets.Count;
                        }
                        else
                        {
                            if (c > 0)
                            {
                                worksheets.Add();
                                worksheet      = workbook.Worksheets[worksheets.Count - 1];
                                worksheet.Name = sheetname + worksheets.Count;
                            }
                        }
                        string allsite = "A1";
                        IRange cell    = worksheet.Cells[allsite];
                        //cell.CopyFromDataTable(allitem[c], SetDataFlags.None);
                        cell.CopyFromDataTable(allitem[c], SetDataFlags.AllText);

                        worksheet.UsedRange.Columns.AutoFit();
                        //high += allitem[c].Rows.Count;
                    }
                }
                else
                {
                    if (columns.Count > 0)
                    {
                        high += 2;
                    }
                    for (int b = 0; b < allitem.Count; b++)
                    {
                        if (b > 0)
                        {
                            high += 1;
                        }
                        string allsite = "A" + high;
                        IRange cell    = worksheet.Cells[allsite];
                        //cell.CopyFromDataTable(allitem[b], SetDataFlags.None);
                        cell.CopyFromDataTable(allitem[b], SetDataFlags.AllText);
                        if (cellText)
                        {
                            for (int i = 1; i <= allitem[0].Rows.Count; i++)
                            {
                                // cell[i, cellInt].NumberFormat = "@";
                                cell[i, cellInt].NumberFormat = "@";
                            }
                        }

                        worksheet.UsedRange.Columns.AutoFit();
                        high += allitem[b].Rows.Count;
                    }
                }
            }
            return(workbook);
        }
Exemplo n.º 25
0
        public SpreadsheetGear.IWorkbook ExportExcel_One(string title, string subtitle, DataTable allitem, string sheetname)
        {
            //创建新的workbook
            SpreadsheetGear.IWorkbook workbook = Factory.GetWorkbook();
            IWorksheet worksheet = workbook.Worksheets[0];

            worksheet.Name = sheetname;
            IWorksheetWindowInfo windowInfo = worksheet.WindowInfo;
            IShapes shapes = worksheet.Shapes;

            while (shapes.Count != 0)
            {
                shapes[0].Delete();
            }
            int    itemcou = allitem.Columns.Count;
            string site    = "A1:" + (char)((64 + itemcou)) + "1";
            string site1   = null;

            if (!string.IsNullOrEmpty(subtitle))
            {
                site1 = "A2:" + (char)((64 + itemcou)) + "2";
            }
            else
            {
                site1 = "A1:" + (char)((64 + itemcou)) + "1";
            }
            //数据处理
            if (!string.IsNullOrEmpty(title))
            {
                IRange cell = worksheet.Cells[site];
                cell.Merge();
                cell.HorizontalAlignment = HAlign.Center;
                cell.VerticalAlignment   = VAlign.Center;
                cell.Value = title;
            }

            if (!string.IsNullOrEmpty(subtitle))
            {
                IRange cell1 = worksheet.Cells[site1];
                cell1.Merge();
                cell1.HorizontalAlignment = HAlign.Center;
                cell1.VerticalAlignment   = VAlign.Center;
                cell1.Value = subtitle;
            }
            if (!string.IsNullOrEmpty(title) && !string.IsNullOrEmpty(subtitle))
            {
                IRange cell2 = worksheet.Cells["A3"];
                cell2.CopyFromDataTable(allitem, SetDataFlags.None);
            }
            else if (!string.IsNullOrEmpty(title) || !string.IsNullOrEmpty(subtitle))
            {
                IRange cell2 = worksheet.Cells["A2"];
                cell2.CopyFromDataTable(allitem, SetDataFlags.None);
            }
            else
            {
                IRange cell2 = worksheet.Cells["A1"];
                cell2.CopyFromDataTable(allitem, SetDataFlags.None);
            }
            worksheet.UsedRange.Columns.AutoFit();

            return(workbook);
        }
Exemplo n.º 26
0
 internal static void Init(ISurface surface, IDrawings drawings, IShapes shapes)
 {
     _graphics = drawings;
      _shapes = shapes;
      X = surface.Width / 2.0;
      Y = surface.Height / 2.0;
      Angle = 0;
      _isPenDown = true;
      Hide();
 }
Exemplo n.º 27
0
 public void TestTriangleInitialization()
 {
     triangle = new Triangle(3, 3, 3);
 }
Exemplo n.º 28
0
        public SpreadsheetGear.IWorkbook BuildSheet(List <SheetModel> sheets)
        {
            //创建新的workbook
            SpreadsheetGear.IWorkbook   workbook   = Factory.GetWorkbook();
            SpreadsheetGear.IWorksheets worksheets = workbook.Worksheets;
            for (int i = 0; i < sheets.Count; i++)
            {
                int high = 1;
                if (i > 0)
                {
                    worksheets.Add();
                }
                IWorksheet worksheet = worksheets[i];
                worksheet.Name = sheets[i].SheetName == null ? "sheet" + (i + 1) : sheets[i].SheetName;
                IWorksheetWindowInfo windowInfo = worksheet.WindowInfo;
                IShapes          shapes         = worksheet.Shapes;
                List <DataModel> dataList       = sheets[i].DataModels;
                for (int j = 0; j < dataList.Count; j++)
                {
                    if (dataList[j].datatype.ToString() != "DataTable")
                    {
                        high += 16;
                        string allsite = "A" + high;
                        IRange cell    = worksheet.Cells[allsite];
                        cell.CopyFromDataTable(dataList[j].Dataseries, SetDataFlags.None);
                        worksheet.UsedRange.Columns.AutoFit();

                        double top         = high - 16.5;
                        double bottom      = high - 1.5;
                        double chartleft   = windowInfo.ColumnToPoints(0.15);
                        double charttop    = windowInfo.RowToPoints(top);
                        double chartright  = windowInfo.ColumnToPoints(7.85);
                        double chartbottom = windowInfo.RowToPoints(bottom);

                        SpreadsheetGear.Charts.IChart chart = shapes.AddChart(chartleft, charttop, chartright - chartleft, chartbottom - charttop).Chart;
                        string site   = ((char)(65 + dataList[j].StartPoint.x)).ToString() + (high + dataList[j].StartPoint.y) + ":" + ((char)(64 + dataList[j].ColumnCount + dataList[j].StartPoint.x)).ToString() + (high + dataList[j].StartPoint.y + dataList[j].RowCount);
                        IRange source = worksheet.Cells[site];
                        chart.SetSourceData(source, RowCol.Columns);
                        switch (dataList[j].datatype.ToString())
                        {
                        case "Column":
                            chart.ChartType = ChartType.ColumnClustered;
                            break;

                        case "Line":
                            chart.ChartType = ChartType.Line;
                            break;

                        case "Radar":
                            chart.ChartType = ChartType.Radar;
                            break;

                        case "Bar":
                            chart.ChartType = ChartType.BarClustered;
                            break;

                        case "BarStacked":
                            chart.ChartType = ChartType.BarStacked;
                            break;

                        case "Pie":
                            chart.ChartType = ChartType.Pie;
                            ISeries seriesTotal = chart.SeriesCollection[0];
                            seriesTotal.HasDataLabels             = true;
                            seriesTotal.DataLabels.ShowPercentage = true;
                            seriesTotal.DataLabels.ShowValue      = false;
                            break;
                        }
                        high += dataList[j].Dataseries.Rows.Count + 1 + sheets[i].space;
                    }
                    else
                    {
                        string allsite = "A" + high;
                        IRange cell    = worksheet.Cells[allsite];
                        //cell.CopyFromDataTable(dataList[j].Dataseries, SetDataFlags.None);
                        cell.CopyFromDataTable(dataList[j].Dataseries, SetDataFlags.AllText);
                        worksheet.UsedRange.Columns.AutoFit();
                        high += dataList[j].Dataseries.Rows.Count + 1 + sheets[i].space;
                    }
                }
            }
            return(workbook);
        }
Exemplo n.º 29
0
        public ActionResult GroupShapes(string Group1, string button)
        {
            if (Group1 == null)
            {
                return(View());
            }
            else if (button == "Input Template")
            {
                //Step 1 : Instantiate the spreadsheet creation engine.
                ExcelEngine excelEngine = new ExcelEngine();
                //Step 2 : Instantiate the excel application object.
                IApplication application = excelEngine.Excel;
                IWorkbook    workbook    = application.Workbooks.Open(ResolveApplicationDataPath(@"GroupShapes.xlsx"));
                return(excelEngine.SaveAsActionResult(workbook, "GroupShapes.xlsx", HttpContext.ApplicationInstance.Response, ExcelDownloadType.PromptDialog, ExcelHttpContentType.Excel2016));
            }
            else
            {
                // The instantiation process consists of two steps.
                // Step 1 : Instantiate the spreadsheet creation engine.
                ExcelEngine excelEngine = new ExcelEngine();

                // Step 2 : Instantiate the excel application object.
                IApplication application = excelEngine.Excel;
                application.DefaultVersion = ExcelVersion.Excel2016;

                // An existing workbook is opened.
                IWorkbook workbook = application.Workbooks.Open(ResolveApplicationDataPath("GroupShapes.xlsx"));

                IWorksheet worksheet;
                try
                {
                    if (Group1 == "Group")
                    {
                        // The first worksheet object in the worksheets collection is accessed.
                        worksheet = workbook.Worksheets[0];
                        IShapes shapes = worksheet.Shapes;

                        IShape[] groupItems;
                        for (int i = 0; i < shapes.Count; i++)
                        {
                            if (shapes[i].Name == "Development" || shapes[i].Name == "Production" || shapes[i].Name == "Sales")
                            {
                                groupItems = new IShape[] { shapes[i], shapes[i + 1], shapes[i + 2], shapes[i + 3], shapes[i + 4], shapes[i + 5] };
                                shapes.Group(groupItems);
                                i = -1;
                            }
                        }

                        groupItems = new IShape[] { shapes[0], shapes[1], shapes[2], shapes[3], shapes[4], shapes[5], shapes[6] };

                        // Group the selected shapes
                        shapes.Group(groupItems);

                        return(excelEngine.SaveAsActionResult(workbook, "GroupShapes.xlsx", HttpContext.ApplicationInstance.Response, ExcelDownloadType.PromptDialog, ExcelHttpContentType.Excel2016));
                    }
                    else if (Group1 == "UngroupAll")
                    {
                        // The second worksheet object in the worksheets collection is accessed.
                        worksheet = workbook.Worksheets[1];
                        IShapes shapes = worksheet.Shapes;

                        // Ungroup group shape and its all the inner shapes.
                        shapes.Ungroup(shapes[0] as IGroupShape, true);
                        worksheet.Activate();

                        return(excelEngine.SaveAsActionResult(workbook, "UngroupShapes.xlsx", HttpContext.ApplicationInstance.Response, ExcelDownloadType.PromptDialog, ExcelHttpContentType.Excel2016));
                    }
                    else if (Group1 == "Ungroup")
                    {
                        // The second worksheet object in the worksheets collection is accessed.
                        worksheet = workbook.Worksheets[1];
                        IShapes shapes = worksheet.Shapes;

                        // Ungroup group shape.
                        shapes.Ungroup(shapes[0] as IGroupShape);
                        worksheet.Activate();

                        return(excelEngine.SaveAsActionResult(workbook, "UngroupShapes.xlsx", HttpContext.ApplicationInstance.Response, ExcelDownloadType.PromptDialog, ExcelHttpContentType.Excel2016));
                    }
                }
                catch (Exception)
                {
                }
            }
            return(View());
        }
Exemplo n.º 30
0
        private void btnConvert_Click(object sender, EventArgs e)
        {
            #region Workbook Initialization
            //New instance of XlsIO is created.[Equivalent to launching MS Excel with no workbooks open].
            //The instantiation process consists of two steps.

            //Step 1 : Instantiate the spreadsheet creation engine.
            ExcelEngine excelEngine = new ExcelEngine();
            //Step 2 : Instantiate the excel application object.
            IApplication application = excelEngine.Excel;

            //Get the path of the Input file
            string inputPath = GetFullTemplatePath("GroupShapes.xlsx");

            // Existing workbook is opened
            IWorkbook workbook = application.Workbooks.Open(inputPath);

            IWorksheet worksheet;

            #endregion

            #region Group Shape

            string fileName = "";

            if (rdbGroup.Checked)
            {
                // The first worksheet object in the worksheets collection is accessed.
                worksheet = workbook.Worksheets[0];
                IShapes shapes = worksheet.Shapes;

                IShape[] groupItems;
                for (int i = 0; i < shapes.Count; i++)
                {
                    if (shapes[i].Name == "Development" || shapes[i].Name == "Production" || shapes[i].Name == "Sales")
                    {
                        groupItems = new IShape[] { shapes[i], shapes[i + 1], shapes[i + 2], shapes[i + 3], shapes[i + 4], shapes[i + 5] };
                        shapes.Group(groupItems);
                        i = -1;
                    }
                }

                groupItems = new IShape[] { shapes[0], shapes[1], shapes[2], shapes[3], shapes[4], shapes[5], shapes[6] };
                shapes.Group(groupItems);

                fileName = "Group.xlsx";
                workbook.SaveAs(fileName);
            }
            else if (rdbUngroupAll.Checked)
            {
                // The second worksheet object in the worksheets collection is accessed.
                worksheet = workbook.Worksheets[1];
                IShapes shapes = worksheet.Shapes;
                shapes.Ungroup(shapes[0] as IGroupShape, true);
                worksheet.Activate();
                fileName = "Ungroup.xlsx";
                workbook.SaveAs(fileName);
            }
            else if (rdbUngroup.Checked)
            {
                // The second worksheet object in the worksheets collection is accessed.
                worksheet = workbook.Worksheets[1];
                IShapes shapes = worksheet.Shapes;
                shapes.Ungroup(shapes[0] as IGroupShape);
                worksheet.Activate();
                fileName = "Ungroup.xlsx";
                workbook.SaveAs(fileName);
            }
            #endregion

            #region Workbook Close and Dispose
            //Close the workbook and excelEngine
            workbook.Close();
            excelEngine.Dispose();
            #endregion

            #region View the Workbook
            //Message box confirmation to view the created spreadsheet.
            if (MessageBox.Show("Do you want to view the workbook?", "Workbook has been saved",
                                MessageBoxButtons.YesNo, MessageBoxIcon.Information)
                == DialogResult.Yes)
            {
                //Launching the HTMl file using the default Application.[MS Excel Or Free ExcelViewer]
#if NETCORE
                System.Diagnostics.Process process = new System.Diagnostics.Process();
                process.StartInfo = new System.Diagnostics.ProcessStartInfo(fileName)
                {
                    UseShellExecute = true
                };
                process.Start();
#else
                Process.Start(fileName);
#endif
                //Exit
                this.Close();
            }
            else
            {
                // Exit
                this.Close();
            }
            #endregion
        }
Exemplo n.º 31
0
 public Slide(int width, int height)
 {
     _width       = width;
     _height      = height;
     _groupShapes = new Shapes();
 }
Exemplo n.º 32
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            // New instance of XlsIO is created.[Equivalent to launching MS Excel with no workbooks open].
            // The instantiation process consists of two steps.

            // Step 1 : Instantiate the spreadsheet creation engine.
            ExcelEngine excelEngine = new ExcelEngine();

            // Step 2 : Instantiate the excel application object.
            IApplication application = excelEngine.Excel;

            // An existing workbook is opened.
            IWorkbook workbook = application.Workbooks.Open(@"..\..\..\..\..\..\..\Common\Data\XlsIO\GroupShapes.xlsx");

            // The first worksheet object in the worksheets collection is accessed.
            IWorksheet worksheet;

            string fileName = string.Empty;

            if (groupRBtn.IsChecked.Value)
            {
                // The first worksheet object in the worksheets collection is accessed.
                worksheet = workbook.Worksheets[0];
                IShapes shapes = worksheet.Shapes;

                IShape[] groupItems;
                for (int i = 0; i < shapes.Count; i++)
                {
                    if (shapes[i].Name == "Development" || shapes[i].Name == "Production" || shapes[i].Name == "Sales")
                    {
                        groupItems = new IShape[] { shapes[i], shapes[i + 1], shapes[i + 2], shapes[i + 3], shapes[i + 4], shapes[i + 5] };
                        shapes.Group(groupItems);
                        i = -1;
                    }
                }

                groupItems = new IShape[] { shapes[0], shapes[1], shapes[2], shapes[3], shapes[4], shapes[5], shapes[6] };
                shapes.Group(groupItems);

                fileName = "Group.xlsx";
                workbook.SaveAs(fileName);
            }
            else if (ungroupRBtnAll.IsChecked.Value)
            {
                // The second worksheet object in the worksheets collection is accessed.
                worksheet = workbook.Worksheets[1];
                IShapes shapes = worksheet.Shapes;
                shapes.Ungroup(shapes[0] as IGroupShape, true);
                worksheet.Activate();
                fileName = "Ungroup.xlsx";
                workbook.SaveAs(fileName);
            }
            else if (ungroupRBtn.IsChecked.Value)
            {
                // The second worksheet object in the worksheets collection is accessed.
                worksheet = workbook.Worksheets[1];
                IShapes shapes = worksheet.Shapes;
                shapes.Ungroup(shapes[0] as IGroupShape);
                worksheet.Activate();
                fileName = "Ungroup.xlsx";
                workbook.SaveAs(fileName);
            }
            //Close the workbook.
            workbook.Close();
            excelEngine.Dispose();

            //Message box confirmation to view the created spreadsheet.
            if (MessageBox.Show("Do you want to view the workbook?", "Workbook has been created",
                                MessageBoxButton.YesNo, MessageBoxImage.Information) == MessageBoxResult.Yes)
            {
                try
                {
                    //Launching the Excel file using the default Application.[MS Excel Or Free ExcelViewer]
                    System.Diagnostics.Process.Start(fileName);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.ToString());
                }
            }
            else
            {
                // Exit
                this.Close();
            }
        }
Exemplo n.º 33
0
        private async void btnGenerateExcel_Click(object sender, RoutedEventArgs e)
        {
            #region Initializing Workbook
            //New instance of XlsIO is created.[Equivalent to launching MS Excel with no workbooks open].
            //The instantiation process consists of two steps.

            //Step 1 : Instantiate the spreadsheet creation engine.
            ExcelEngine excelEngine = new ExcelEngine();
            //Step 2 : Instantiate the Excel application object.
            IApplication application = excelEngine.Excel;

            application.DefaultVersion = ExcelVersion.Excel2016;

            Assembly  assembly     = typeof(FunnelChart).GetTypeInfo().Assembly;
            string    resourcePath = "Syncfusion.SampleBrowser.UWP.XlsIO.XlsIO.Tutorials.Samples.Assets.Resources.Templates.GroupShapes.xlsx";
            Stream    fileStream   = assembly.GetManifestResourceStream(resourcePath);
            IWorkbook workbook     = await application.Workbooks.OpenAsync(fileStream);

            IWorksheet worksheet;
            #endregion

            #region Group Shape Creation

            if (this.rdBtnGroup.IsChecked != null && this.rdBtnGroup.IsChecked.Value)
            {
                // The first worksheet object in the worksheets collection is accessed.
                worksheet = workbook.Worksheets[0];
                IShapes shapes = worksheet.Shapes;

                IShape[] groupItems;
                for (int i = 0; i < shapes.Count; i++)
                {
                    if (shapes[i].Name == "Development" || shapes[i].Name == "Production" || shapes[i].Name == "Sales")
                    {
                        groupItems = new IShape[] { shapes[i], shapes[i + 1], shapes[i + 2], shapes[i + 3], shapes[i + 4], shapes[i + 5] };
                        shapes.Group(groupItems);
                        i = -1;
                    }
                }

                groupItems = new IShape[] { shapes[0], shapes[1], shapes[2], shapes[3], shapes[4], shapes[5], shapes[6] };
                shapes.Group(groupItems);
            }
            else if (this.rdBtnUngroupAll.IsChecked != null && this.rdBtnUngroupAll.IsChecked.Value)
            {
                // The second worksheet object in the worksheets collection is accessed.
                worksheet = workbook.Worksheets[1];
                IShapes shapes = worksheet.Shapes;
                shapes.Ungroup(shapes[0] as IGroupShape, true);
                worksheet.Activate();
            }
            else if (this.rdBtnUngroup.IsChecked != null && this.rdBtnUngroup.IsChecked.Value)
            {
                // The second worksheet object in the worksheets collection is accessed.
                worksheet = workbook.Worksheets[1];
                IShapes shapes = worksheet.Shapes;
                shapes.Ungroup(shapes[0] as IGroupShape);
                worksheet.Activate();
            }
            #endregion

            #region Save the Workbook
            StorageFile storageFile;
            if (!(Windows.Foundation.Metadata.ApiInformation.IsTypePresent("Windows.Phone.UI.Input.HardwareButtons")))
            {
                FileSavePicker savePicker = new FileSavePicker();
                savePicker.SuggestedStartLocation = PickerLocationId.Desktop;
                savePicker.SuggestedFileName      = "GroupShapes";
                savePicker.FileTypeChoices.Add("Excel Files", new List <string>()
                {
                    ".xlsx",
                });
                storageFile = await savePicker.PickSaveFileAsync();
            }
            else
            {
                StorageFolder local = Windows.Storage.ApplicationData.Current.LocalFolder;
                storageFile = await local.CreateFileAsync("GroupShapes.xlsx", CreationCollisionOption.ReplaceExisting);
            }

            if (storageFile != null)
            {
                //Saving the workbook
                await workbook.SaveAsAsync(storageFile);

                workbook.Close();
                excelEngine.Dispose();

                MessageDialog msgDialog = new MessageDialog("Do you want to view the Document?", "File has been saved successfully.");

                UICommand yesCmd = new UICommand("Yes");
                msgDialog.Commands.Add(yesCmd);
                UICommand noCmd = new UICommand("No");
                msgDialog.Commands.Add(noCmd);
                IUICommand cmd = await msgDialog.ShowAsync();

                if (cmd == yesCmd)
                {
                    // Launch the saved file
                    bool success = await Windows.System.Launcher.LaunchFileAsync(storageFile);
                }
            }
            else
            {
                workbook.Close();
                excelEngine.Dispose();
            }
            #endregion
        }