Esempio n. 1
0
        static void Main(string[] args)
        {
            try
            {
                Book book = new BinBook();

                Font font = book.addFont();
                font.size = 36;

                Format format = book.addFormat();
                format.alignH = AlignH.ALIGNH_CENTER;
                format.setBorder(BorderStyle.BORDERSTYLE_MEDIUMDASHDOTDOT);
                format.setBorderColor(Color.COLOR_RED);
                format.font = font;

                Sheet sheet = book.addSheet("Sheet1");
                sheet.writeStr(2, 1, "Format", format);
                sheet.setCol(1, 1, 25);

                book.save("format.xls");

                System.Diagnostics.Process.Start("format.xls");
            }
            catch (System.Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            try
            {
                Book book = new BinBook();

                int f1 = book.addCustomNumFormat("0.0");
                int f2 = book.addCustomNumFormat("0.00");
                int f3 = book.addCustomNumFormat("0.000");
                int f4 = book.addCustomNumFormat("0.0000");
                int f5 = book.addCustomNumFormat("#,###.00 $");
                int f6 = book.addCustomNumFormat("#,###.00 $[Black][<1000];#,###.00 $[Red][>=1000]");

                Format format1 = book.addFormat();
                format1.setNumFormat(f1);

                Format format2 = book.addFormat();
                format2.setNumFormat(f2);

                Format format3 = book.addFormat();
                format3.setNumFormat(f3);

                Format format4 = book.addFormat();
                format4.setNumFormat(f4);

                Format format5 = book.addFormat();
                format5.setNumFormat(f5);

                Format format6 = book.addFormat();
                format6.setNumFormat(f6);

                Sheet sheet = book.addSheet("Custom formats");
                sheet.setCol(0, 20);

                sheet.writeNum(2, 0, 25.718, format1);
                sheet.writeNum(3, 0, 25.718, format2);
                sheet.writeNum(4, 0, 25.718, format3);
                sheet.writeNum(5, 0, 25.718, format4);

                sheet.writeNum(7, 0, 1800.5, format5);

                sheet.writeNum(9, 0, 500, format6);
                sheet.writeNum(10, 0, 1600, format6);

                book.save("custom.xls");

                System.Diagnostics.Process.Start("custom.xls");
            }
            catch (System.Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
Esempio n. 3
0
        static void Main(string[] args)
        {
            try
            {
                Book  book  = new BinBook();
                Sheet sheet = book.addSheet("Sheet1");

                sheet.writeStr(2, 1, "Hello, World !");
                sheet.writeNum(3, 1, 1000);

                Format dateFormat = book.addFormat();
                dateFormat.setNumFormat(NumFormat.NUMFORMAT_DATE);
                sheet.writeNum(4, 1, book.datePack(2008, 4, 29), dateFormat);
                sheet.setCol(1, 1, 12);

                book.save("example.xls");

                System.Diagnostics.Process.Start("example.xls");
            }
            catch (System.Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
Esempio n. 4
0
        static void test(int number)
        {
            Console.WriteLine("---------------------------------");
            if (number == 1)
            {
                Console.WriteLine("           strings               ");
            }
            else
            {
                Console.WriteLine("           numbers               ");
            }
            Console.WriteLine("---------------------------------\n");

            Book  book  = new BinBook();
            Sheet sheet = book.addSheet("Sheet1");

            Console.Write("writing {0:#,###} cells... ", (maxRow - 1) * maxCol);
            DateTime t1 = DateTime.Now;

            if (number == 1)
            {
                for (int row = 1; row < maxRow; ++row)
                {
                    for (int col = 0; col < maxCol; ++col)
                    {
                        sheet.writeStr(row, col, makeString());
                    }
                }
            }
            else
            {
                for (int row = 1; row < maxRow; ++row)
                {
                    for (int col = 0; col < maxCol; ++col)
                    {
                        sheet.writeNum(row, col, 1234);
                    }
                }
            }

            Console.WriteLine("ok");

            DateTime t2 = DateTime.Now;
            TimeSpan d  = t2 - t1;

            Console.WriteLine("time: {0} sec", d.TotalSeconds);

            double n = (maxRow - 1) * maxCol / d.TotalSeconds;

            Console.WriteLine("speed: {0:#,###} cells/sec", n);
            Console.WriteLine();

            Console.Write("saving... ");

            if (number == 1)
            {
                book.save("perfstr.xls");
            }
            else
            {
                book.save("perfnum.xls");
            }

            Console.WriteLine("ok");

            DateTime t3 = DateTime.Now;

            Console.WriteLine("time: {0} sec", (t3 - t2).TotalSeconds);
            Console.WriteLine();

            Console.WriteLine("total time: {0} sec", (t3 - t1).TotalSeconds);

            d = t3 - t1;
            n = (maxRow - 1) * maxCol / d.TotalSeconds;
            Console.WriteLine("speed with saving on disk: {0:#,###} cells/sec\n", n);

            GC.Collect();
            GC.WaitForPendingFinalizers();
            GC.Collect();
        }
Esempio n. 5
0
        static void Main(string[] args)
        {
            try
            {
                Book book = new BinBook();

                Font boldFont = book.addFont();
                boldFont.bold = true;

                Font titleFont = book.addFont();
                titleFont.name = "Arial Black";
                titleFont.size = 16;

                Format titleFormat = book.addFormat();
                titleFormat.font = titleFont;

                Format headerFormat = book.addFormat();
                headerFormat.alignH = AlignH.ALIGNH_CENTER;
                headerFormat.setBorder(BorderStyle.BORDERSTYLE_THIN);
                headerFormat.font                   = boldFont;
                headerFormat.fillPattern            = FillPattern.FILLPATTERN_SOLID;
                headerFormat.patternForegroundColor = Color.COLOR_TAN;

                Format descriptionFormat = book.addFormat();
                descriptionFormat.borderLeft = BorderStyle.BORDERSTYLE_THIN;

                Format amountFormat = book.addFormat();
                amountFormat.setNumFormat(NumFormat.NUMFORMAT_CURRENCY_NEGBRA);
                amountFormat.borderLeft  = BorderStyle.BORDERSTYLE_THIN;
                amountFormat.borderRight = BorderStyle.BORDERSTYLE_THIN;

                Format totalLabelFormat = book.addFormat();
                totalLabelFormat.borderTop = BorderStyle.BORDERSTYLE_THIN;
                totalLabelFormat.alignH    = AlignH.ALIGNH_RIGHT;
                totalLabelFormat.font      = boldFont;

                Format totalFormat = book.addFormat();
                totalFormat.setNumFormat(NumFormat.NUMFORMAT_CURRENCY_NEGBRA);
                totalFormat.setBorder(BorderStyle.BORDERSTYLE_THIN);
                totalFormat.font                   = boldFont;
                totalFormat.fillPattern            = FillPattern.FILLPATTERN_SOLID;
                totalFormat.patternForegroundColor = Color.COLOR_YELLOW;

                Format signatureFormat = book.addFormat();
                signatureFormat.alignH    = AlignH.ALIGNH_CENTER;
                signatureFormat.borderTop = BorderStyle.BORDERSTYLE_THIN;

                Sheet sheet = book.addSheet("Invoice");

                sheet.writeStr(2, 1, "Invoice No. 3568", titleFormat);

                sheet.writeStr(4, 1, "Name: John Smith");
                sheet.writeStr(5, 1, "Address: San Ramon, CA 94583 USA");

                sheet.writeStr(7, 1, "Description", headerFormat);
                sheet.writeStr(7, 2, "Amount", headerFormat);

                sheet.writeStr(8, 1, "Ball-Point Pens", descriptionFormat);
                sheet.writeNum(8, 2, 85, amountFormat);
                sheet.writeStr(9, 1, "T-Shirts", descriptionFormat);
                sheet.writeNum(9, 2, 150, amountFormat);
                sheet.writeStr(10, 1, "Tea cups", descriptionFormat);
                sheet.writeNum(10, 2, 45, amountFormat);

                sheet.writeStr(11, 1, "Total:", totalLabelFormat);
                sheet.writeNum(11, 2, 280, totalFormat);

                sheet.writeStr(14, 2, "Signature", signatureFormat);

                sheet.setCol(1, 1, 40);
                sheet.setCol(2, 2, 15);

                book.save("invoice.xls");

                System.Diagnostics.Process.Start("invoice.xls");
            }
            catch (System.Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
        public static bool ExportToExcel(Application rvtApp, Document doc, bool includeFireRating, bool includeComments)
        {
            Console.WriteLine("start create Excel.");
            Book book = new BinBook(); // use XmlBook() for xlsx

            if (null == book)
            {
                throw new InvalidOperationException("Could not create BinBook.");
            }

            if (includeFireRating)
            {
                Sheet sheet = book.addSheet("Door Type FireRating");
                sheet.writeStr(1, 1, "Element ID");
                sheet.writeStr(1, 2, "Unique ID");
                sheet.writeStr(1, 3, "Family Name");
                sheet.writeStr(1, 4, "Family Type");
                sheet.writeStr(1, 5, FireRating);

                List <Element> elems = GetTargetElements(doc, BuiltInCategory.OST_Doors, false);
                // Loop through all elements and export each to an Excel row

                int row = 2;
                foreach (Element e in elems)
                {
                    sheet.writeNum(row, 1, e.Id.IntegerValue);
                    sheet.writeStr(row, 2, e.UniqueId);

                    FamilySymbol symbol = e as FamilySymbol;
                    if (null != symbol)
                    {
                        sheet.writeStr(row, 3, symbol.FamilyName);
                        sheet.writeStr(row, 4, symbol.Name);

                        // FireRating:
                        Parameter fireRatingParam = symbol.get_Parameter(BuiltInParameter.DOOR_FIRE_RATING);
                        if (fireRatingParam != null)
                        {
                            sheet.writeStr(row, 5, fireRatingParam.AsString());
                            Console.WriteLine("write row " + row.ToString() + ":" + e.Id.IntegerValue.ToString() + "," + e.UniqueId + "," + symbol.FamilyName + "," + symbol.Name + "," + fireRatingParam.AsString());
                        }
                    }
                    ++row;
                }
            }

            if (includeComments)
            {
                Sheet sheet = book.addSheet("Door Instance Comments");
                sheet.writeStr(1, 1, "Element ID");
                sheet.writeStr(1, 2, "Unique ID");
                sheet.writeStr(1, 3, "Instance Name");
                sheet.writeStr(1, 4, Comments);

                Console.WriteLine("write comments");

                List <Element> elems = GetTargetElements(doc, BuiltInCategory.OST_Doors, true);
                // Loop through all elements and export each to an Excel row
                int row = 2;
                foreach (Element e in elems)
                {
                    sheet.writeNum(row, 1, e.Id.IntegerValue);
                    sheet.writeStr(row, 2, e.UniqueId);
                    sheet.writeStr(row, 3, e.Name);

                    // Comments:
                    Parameter commentsParam = e.get_Parameter(
                        BuiltInParameter.ALL_MODEL_INSTANCE_COMMENTS);
                    if (null != commentsParam)
                    {
                        sheet.writeStr(row, 4, commentsParam.AsString());
                        Console.WriteLine("write row " + row.ToString() + ":" + e.Id.IntegerValue.ToString() + "," + e.UniqueId + "," + e.Name + "," + commentsParam.AsString());
                    }
                    ++row;
                }
            }
            book.save("result.xls");
            Console.WriteLine("Excel App is created");
            return(true);
        }
        public MainWindowViewModel()
        {
            MoistureContent = "0";
            Data            = new ObservableCollection <Tuple <double, double> >()
            {
            };

            Series = new WpfPlot();
            Series.plt.Title("Liquid limit test", fontSize: 20);
            Series.plt.XLabel("Number of blows (N)", bold: true);
            Series.plt.YLabel("Moisture content (%)", bold: true);
            Series.plt.Ticks(logScaleY: true);
            Series.Configure(lockHorizontalAxis: true, lockVerticalAxis: true);

            Series.plt.AxisAuto(horizontalMargin: 0, verticalMargin: 0.9);

            //_dataPlot = Series.plt.PlotScatter(_data.OrderBy(d => d.Item1).Select(d => d.Item1).ToArray(), _data.OrderBy(d => d.Item1).Select(d => d.Item2).ToArray());

            ClearDataCommand = new DelegateCommand(() =>
            {
                NumberOfBlows   = 0;
                MoistureContent = "";
                Data.Clear();
                Series.plt.Clear();

                if (_dataPlot == null)
                {
                    _dataPlot = Series.plt.PlotScatter(Data.OrderBy(d => d.Item1).Select(d => d.Item1).ToArray(), Data.OrderBy(d => d.Item1).Select(d => d.Item2).ToArray());
                }
            });

            AddDataCommand = new DelegateCommand(() =>
            {
                Data.Add(new Tuple <double, double>(NumberOfBlows, Double.Parse(MoistureContent)));
                if (Data.Count() >= 2)
                {
                    Series.plt.Clear();
                    _dataPlot = Series.plt.PlotScatter(Data.OrderBy(d => d.Item1).Select(d => d.Item1).ToArray(), Data.OrderBy(d => d.Item1).Select(d => d.Item2).ToArray(), color: System.Drawing.Color.Gray, lineStyle: LineStyle.Dash);

                    DrawRegressionLine();
                }

                NumberOfBlows   = 0;
                MoistureContent = "0";
            });

            ExportCommand = new DelegateCommand(() =>
            {
                var dialog    = new SaveFileDialog();
                dialog.Filter = "Excel file (*.xls)|*.xls";
                dialog.ShowDialog();
                ;

                var fileName = dialog.FileName;

                if (String.IsNullOrEmpty(fileName))
                {
                    return;
                }

                Series.plt.SaveFig($"{fileName}.png");

                var book = new BinBook();

                var id = book.addPicture(fileName + ".png");

                var sheet = book.addSheet("Chart");
                sheet.setPicture(10, 3, id);

                book.save(fileName);
            });
        }
        public MainWindowViewModel()
        {
            Data = new ObservableCollection <Tuple <double, double> >();

            Series = new WpfPlot();
            Series.plt.Title("Potential Expansivess", bold: true, fontSize: 22);
            Series.plt.XLabel("Clay fraction of whole sample", bold: true);
            Series.plt.YLabel("PI of whole sample", bold: true);


            Series.plt.AxisBounds(0, _xMax, 0, _yMax);
            Series.Configure(lockHorizontalAxis: true, lockVerticalAxis: true);
            Series.plt.Grid(xSpacing: 10, ySpacing: 10, lineWidth: 2);
            // Series.plt.AxisZoom(0, 0, -20, -20);
            //Series.Width = 800;

            AddDataCommand = new DelegateCommand(() =>
            {
                Data.Add(new Tuple <double, double>(ClayFractionOfWholeSample, PiOfWholeSample));

                Series.plt.PlotPoint(ClayFractionOfWholeSample, PiOfWholeSample, GetColor(), 15);
                Series.plt.PlotText(_pointLabel, ClayFractionOfWholeSample - 0.5, PiOfWholeSample + 1, System.Drawing.Color.Black);

                Series.Render();
            });

            ClearDataCommand = new DelegateCommand(() =>
            {
                ClayFractionOfWholeSample = 0;
                PiOfWholeSample           = 0;

                Data.Clear();
                Series.plt.Clear();
                DrawAbaque();
                Series.plt.AxisBounds(0, _xMax, 0, _yMax);
                Series.Render();
            });

            ExportCommand = new DelegateCommand(() =>
            {
                var dialog    = new SaveFileDialog();
                dialog.Filter = "Excel file (*.xls)|*.xls";
                dialog.ShowDialog();
                ;

                var fileName = dialog.FileName;

                if (String.IsNullOrEmpty(fileName))
                {
                    return;
                }

                Series.plt.SaveFig($"{fileName}.png");

                var book = new BinBook();

                var id = book.addPicture(fileName + ".png");

                var sheet = book.addSheet("Chart");
                sheet.setPicture(10, 3, id);

                book.save(fileName);
            });

            DrawAbaque();
        }