示例#1
0
 private static void loadCustomFunctions(IWorkbookSet books)
 {
     books.Add(GetEQ1.geteq1);
     books.Add(GetEQ2.geteq2);
     books.Add(GetEQH.geteqh);
     books.Add(GetEQV.geteqv);
     books.Add(Partlength.PL);
     books.Add(Partwidth.pw);
     books.Add(PartQuantity.pq);
     books.Add(PARENTNAME.pname);
     books.Add(PartThickness.PT);
     books.Add(PartThicknessM.PTM);
     books.Add(Radians.radians);
     books.Add(Degrees.degrees);
     //books.Add(fABS.fABS);
     //books.Add(fACOS.fACOS);
     //books.Add(fAnd.fAnd);
     //books.Add(fASin.fASin);
     //books.Add(fAtan.fAtan);
     books.Add(PNT.pnt);
     books.Add(Vectors.vectors);
     books.Add(GETBULGE.getbulge);
     books.Add(GETBULGEA.getbulgea);
     books.Add(GETARCALTITUDE.getarcaltitude);
     books.Add(GETARCANGLE.getarcangle);
     books.Add(GETARCCHORD.getarcchord);
     books.Add(GETARCLENGTH.getarclength);
     books.Add(GETARCRADIUS.getarcradius);
     books.Add(RANGETOSTRING.rangetostring);
     books.Add(MyTitle.myTitle);
 }
 private static void loadCustomFunctions(IWorkbookSet books)
 {
     books.Add(GetEQ1.geteq1);
     books.Add(GetEQ2.geteq2);
     books.Add(GetEQH.geteqh);
     books.Add(GetEQV.geteqv);
     books.Add(Partlength.PL);
     books.Add(Partwidth.pw);
     books.Add(PartQuantity.pq);
     books.Add(PARENTNAME.pname);
     books.Add(PartThickness.PT);
     books.Add(PartThicknessM.PTM);
     books.Add(Radians.radians);
     books.Add(Degrees.degrees);
     //books.Add(fABS.fABS);
     //books.Add(fACOS.fACOS);
     //books.Add(fAnd.fAnd);
     //books.Add(fASin.fASin);
     //books.Add(fAtan.fAtan);
     books.Add(PNT.pnt);
     books.Add(Vectors.vectors);
     books.Add(GETBULGE.getbulge);
     books.Add(GETBULGEA.getbulgea);
     books.Add(GETARCALTITUDE.getarcaltitude);
     books.Add(GETARCANGLE.getarcangle);
     books.Add(GETARCCHORD.getarcchord);
     books.Add(GETARCLENGTH.getarclength);
     books.Add(GETARCRADIUS.getarcradius);
     books.Add(RANGETOSTRING.rangetostring);
     books.Add(MyTitle.myTitle);
 }
        public SubPromptWindow(Logger logger, App app, string subCutxFilePath, IWorkbookSet books, SubassemblyItem item)
            : this(logger, app)
        {
            this.Manager = new PromptsViewModel(subCutxFilePath, item.Width.PropertyValue, item.Height.PropertyValue, item.Depth.PropertyValue, books, logger);

            Init();
        }
示例#4
0
        public SubPromptWindow(Logger logger, App app, string subCutxFilePath, IWorkbookSet books, SubassemblyItem item)
            : this(logger, app)
        {
            this.Manager = new PromptsViewModel(subCutxFilePath, item.Width.PropertyValue, item.Height.PropertyValue, item.Depth.PropertyValue, books, logger);

            Init();
        }
示例#5
0
        public IHttpActionResult CalculateSpf(string acquisitionCosts, string loanType)
        {
            //return Ok(new { Message = "Call success"});

            string calcSpreadSheet = new ResourcesHelper().GetSpfSpreadSheetFileName();

            IWorkbookSet workbookSet = Factory.GetWorkbookSet();

            workbookSet.Calculation           = Calculation.Manual;
            workbookSet.BackgroundCalculation = true;

            IWorkbook workbook = workbookSet.Workbooks.Open(calcSpreadSheet);
            //IWorkbook workbook = Factory.GetWorkbook(calcSpreadSheet, System.Globalization.CultureInfo.CurrentCulture);
            IWorksheet worksheet = workbook.Worksheets["Inputs"];
            IRange     cells     = worksheet.Cells;

            cells["B2"].Formula  = acquisitionCosts;
            cells["E10"].Formula = loanType.ToUpper() == "I" ? "Interest Only" : "Amortising";

            workbookSet.Calculate();

            string iru             = cells["H4"].Text;
            string non_utilisation = cells["H5"].Text;
            string arrangementfee  = cells["H6"].Text;
            string totalCosts      = cells["H7"].Text;

            decimal.TryParse(totalCosts, out var totalPaymentsParsed);

            File.Delete(calcSpreadSheet);

            return(Ok(new { acquisitionCosts, iru, non_utilisation, arrangementfee, totalCosts }));
        }
示例#6
0
        /// <summary>
        /// Creates an Excel document with headers as in the headers-parameters.
        /// The rows of data will be filled with data from the data-parameter.
        /// Name of the sheet will be set to sheetName.
        /// The document is written to the given stream.
        /// </summary>
        /// <param name="streamToWriteOutputTo"></param>
        /// <param name="headers"></param>
        /// <param name="data"></param>
        /// <param name="sheetName"></param>
        public static void ExportList(Stream streamToWriteOutputTo, List <string> headers, List <List <string> > data, string sheetName)
        {
            IWorkbookSet workBook = Factory.GetWorkbookSet();
            IWorkbook    iBook    = workBook.Workbooks.Add();
            IWorksheet   iSheet   = iBook.Worksheets.Add();

            iSheet.Name = sheetName;
            IRange cells     = iSheet.Cells;
            int    cellIndex = 0;

            foreach (string header in headers)
            {
                cells[0, cellIndex++].Value = header;
            }
            cells[0, 0, 0, cellIndex].Font.Bold = true;
            int rowIndex = 1;

            foreach (List <string> strings in data)
            {
                cellIndex = 0;
                foreach (string s in strings)
                {
                    cells[rowIndex, cellIndex].NumberFormat = "@";
                    cells[rowIndex, cellIndex++].Value      = s;
                }
                rowIndex++;
            }
            iBook.SaveToStream(streamToWriteOutputTo, FileFormat.Excel8);
        }
        public void DrawAndSaveAs2(Product product, IWorkbookSet bookSet)
        {
            if (File.Exists(filePath))
            { throw new Exception("已经存在temp.dwg,请保证已经删除"); }

            //TODO:Not here
            product.Parts.ForEach(it => it.CalculateLocationInfo(Point3d.Origin, 0));

            using (Database db = new Database())
            using (Transaction acTrans = db.TransactionManager.StartTransaction())
            {
                BlockTable bt = (BlockTable)acTrans.GetObject(db.BlockTableId, OpenMode.ForRead);
                BlockTableRecord btr = (BlockTableRecord)acTrans.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite);

                foreach (var part in product.Parts)
                {
                    Solid3d panel = new Solid3d();
                    panel.CreateBox(part.Length, part.Width, part.Thickness);

                    panel.TransformBy(Matrix3d.Rotation(part.XRotation * Math.PI / 180, Vector3d.XAxis, Point3d.Origin));
                    panel.TransformBy(Matrix3d.Rotation(part.YRotation * Math.PI / 180, Vector3d.YAxis, Point3d.Origin));
                    panel.TransformBy(Matrix3d.Rotation(part.ZRotation * Math.PI / 180, Vector3d.ZAxis, Point3d.Origin));

                    var moveVector = new Vector3d();
                    panel.TransformBy(Matrix3d.Displacement(part.CenterVector));

                    btr.AppendEntity(panel);
                    acTrans.AddNewlyCreatedDBObject(panel, true);
                }

                acTrans.Commit();

                db.SaveAs(filePath, DwgVersion.Newest);
            }
        }
示例#8
0
        public static IWorkbookSet GetProductBaseicBookSet(string productCutx, string globalGvfx, string cutpartsCtpx, string hardwareHwrx, string doorstyleDrx, string edgeEdgx)
        {
            IWorkbookSet books = Factory.GetWorkbookSet();
            IWorkbook    bookL = books.Workbooks.Open(productCutx);

            bookL.FullName = "L";
            var bookG = books.Workbooks.Open(globalGvfx);

            bookG.FullName = "G";
            var bookM = books.Workbooks.Open(cutpartsCtpx);

            bookM.FullName = "M";
            var bookE = books.Workbooks.Open(edgeEdgx);

            bookE.FullName = "E";
            var bookH = books.Workbooks.Open(hardwareHwrx);

            bookH.FullName = "H";
            var bookD = books.Workbooks.Open(doorstyleDrx);

            bookD.FullName = "D";

            loadCustomFunctions(books);

            return(books);
        }
示例#9
0
        private void validateBookset(IWorkbookSet bookSet)
        {
            Logger.GetLogger().Debug("Validating the workbook set...");

            string[] keyIndexs = new string[] { "L", "G", "M", "E", "D", "H" };
            foreach (string i in keyIndexs)
            {
                if (bookSet.Workbooks[i] == null)
                {
                    throw new Exception(string.Format("The book {0} not found in product bookset.", i));
                }
            }
        }
示例#10
0
        public void Import(Stream stream, Action <int, int> progressCallback = null)
        {
            IWorkbookSet workbookSet = Factory.GetWorkbookSet();

            workbookSet.CalculationOnDemand = true;
            workbook = workbookSet.Workbooks.OpenFromStream(stream);
            workbookSet.CalculateFullRebuild();
            workbookNamesCount = workbook.Names.Count;
            Logger logger = LogManager.GetLogger("Generator");

            logger.Debug("Found {0} data elements", workbookNamesCount);
            if (progressCallback != null)
            {
                progressCallback(0, workbookNamesCount);
            }
        }
示例#11
0
        public IEnumerable <ModelError> Analysis(Product product, IWorkbookSet bookSet)
        {
            try
            {
                validateBookset(bookSet);
                this.workBookSet = bookSet;

                product.ClearData();

                var errors = getProductParts(product);



                return(errors);
            }
            catch (Exception error)
            {
                throw new Exception("Error occures when analysising product:" + product.Description, error);
            }
        }
        protected IWorkbook InitializeWorkBook()
        {
            IWorkbookSet workbook_set  = null;
            string       template_path = null;

            if (!string.IsNullOrEmpty(TemplateName))
            {
                // Parse the templates path.
                template_path = TextParser.Parse(TemplateName, DrivingData, SharedData, ModuleCommands);

                // Check for the file expecting relative path.
                if (System.IO.File.Exists(System.IO.Path.GetFullPath(template_path)))
                {
                    TemplateName = System.IO.Path.GetFullPath(template_path);
                }
                // Check for the file from absolute path.
                else if (System.IO.File.Exists(template_path))
                {
                    TemplateName = template_path;
                }
                // Check for the file two layers up incase we are in the bin/debug|release folder.
                else if (System.IO.File.Exists(@"..\..\" + template_path))
                {
                    TemplateName = System.IO.Path.GetFullPath(@"..\..\" + template_path);
                }
                else
                {
                    throw new Exception(string.Format("The excel template file '{0}' was not found.", template_path));
                }
            }

            workbook_set = SpreadsheetGear.Factory.GetWorkbookSet();

            // Copy the template to the workbook.
            if (!string.IsNullOrEmpty(TemplateName))
            {
                return(workbook_set.Workbooks.Open(TemplateName));
            }

            return(workbook_set.Workbooks.Add());
        }
示例#13
0
        public static void Export(string fileName, object record)
        {
            var          fn      = Path.GetDirectoryName(fileName) + "\\" + Path.GetFileNameWithoutExtension(fileName);
            IWorkbookSet bookSet = Factory.GetWorkbookSet();
            IWorkbook    book    = bookSet.Workbooks.Add();

            if (fileName.EndsWith(".xls"))
            {
                book.SaveAs(fn, FileFormat.Excel8);
            }
            else
            {
                book.SaveAs(fn + ".xls", FileFormat.Excel8);
            }

            //SetIndexColumnInExcelFile(book, record);
            SetDateColumnInExcelFile(book, record);
            SetOrdinateColumnInExcelFile(book, record);
            SetValueColumnInExcelFile(book, record);
            book.Save();
            book.Close();
        }
示例#14
0
        public void DrawAndSaveAs2(Product product, IWorkbookSet bookSet)
        {
            if (File.Exists(filePath))
            {
                throw new Exception("已经存在temp.dwg,请保证已经删除");
            }

            //TODO:Not here
            product.Parts.ForEach(it => it.CalculateLocationInfo(Point3d.Origin, 0));

            using (Database db = new Database())
                using (Transaction acTrans = db.TransactionManager.StartTransaction())
                {
                    BlockTable       bt  = (BlockTable)acTrans.GetObject(db.BlockTableId, OpenMode.ForRead);
                    BlockTableRecord btr = (BlockTableRecord)acTrans.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite);

                    foreach (var part in product.Parts)
                    {
                        Solid3d panel = new Solid3d();
                        panel.CreateBox(part.Length, part.Width, part.Thickness);

                        panel.TransformBy(Matrix3d.Rotation(part.XRotation * Math.PI / 180, Vector3d.XAxis, Point3d.Origin));
                        panel.TransformBy(Matrix3d.Rotation(part.YRotation * Math.PI / 180, Vector3d.YAxis, Point3d.Origin));
                        panel.TransformBy(Matrix3d.Rotation(part.ZRotation * Math.PI / 180, Vector3d.ZAxis, Point3d.Origin));

                        var moveVector = new Vector3d();
                        panel.TransformBy(Matrix3d.Displacement(part.CenterVector));

                        btr.AppendEntity(panel);
                        acTrans.AddNewlyCreatedDBObject(panel, true);
                    }

                    acTrans.Commit();

                    db.SaveAs(filePath, DwgVersion.Newest);
                }
        }
示例#15
0
        public static List <ChartSeriesElement> InsertData(DataElement data, Stream inputStream, Stream outputStream)
        {
            List <ChartSeriesElement> series = new List <ChartSeriesElement>();
            IWorkbookSet workbookSet         = Factory.GetWorkbookSet();
            IWorkbook    workbook            = workbookSet.Workbooks.OpenFromStream(inputStream);
            IWorksheet   worksheet           = workbook.Worksheets[0];

            worksheet.UsedRange.Clear();
            int    rowNo = 0, columnNo = 0;
            string axisDataFormula = null;

            rowNo++;
            axisDataFormula = worksheet.Cells[1, 0, data.Rows.Count, 0].Address;
            foreach (Row row in data.Rows)
            {
                if (string.IsNullOrEmpty(row.MappedHeader))
                {
                    worksheet.Cells[rowNo, columnNo].Value = row.Header;
                }
                else
                {
                    worksheet.Cells[rowNo, columnNo].Value = row.MappedHeader;
                }
                rowNo++;
            }
            columnNo++;
            rowNo = 0;
            //}
            var columnsToInclude = data.Columns.ToList();

            for (int colInd = 0; colInd < columnsToInclude.Count; colInd++)
            {
                string seriesTextFormula = null;
                string valuesFormula     = null;
                Index  columnIndex       = null;
                worksheet.Cells[rowNo, columnNo].Value = columnsToInclude[colInd].Header;
                rowNo++;
                seriesTextFormula = worksheet.Cells[0, columnNo].Address;
                valuesFormula     = worksheet.Cells[1, columnNo, data.Rows.Count, columnNo].Address;
                if (string.IsNullOrEmpty((columnsToInclude[colInd].Header)))
                {
                    columnIndex = new Index(colInd)
                    {
                        IsCore = columnsToInclude[colInd].IsCore, IsHidden = columnsToInclude[colInd].IsHidden
                    };
                }
                else
                {
                    columnIndex = new Index(columnsToInclude[colInd].Header)
                    {
                        IsCore = columnsToInclude[colInd].IsCore, IsHidden = columnsToInclude[colInd].IsHidden
                    };
                }
                for (int i = 0; i < data.Rows.Count; i++)
                {
                    worksheet.Cells[rowNo, columnNo].Value = columnsToInclude[colInd].Data[i];
                    rowNo++;
                }
                series.Add(new ChartSeriesElement {
                    CategoryAxisDataAddress = worksheet.Name + "!" + axisDataFormula, SeriesTextAddress = worksheet.Name + "!" + seriesTextFormula, ValuesAddress = worksheet.Name + "!" + valuesFormula, ColumnIndex = columnIndex
                });
                columnNo++;
                rowNo = 0;
            }
            workbook.SaveToStream(outputStream, FileFormat.OpenXMLWorkbook);
            return(series);
        }
        public List<ModelError> GetPartsFromOneLine(IRange partRange, IProduct product, List<Part> parts, IWorkbookSet books, List<Material> tempMaterials, List<EdgeBanding> tempEdgebandings)
        {
            List<ModelError> errors = new List<ModelError>();

            PartChecker check = new PartChecker(partRange, errors);

            string partName = check.PartName();
            int qty = check.Qty();
            if (qty <= 0)
            {
                return errors;
            }

            double width = check.Width();
            double length = check.Length();

            Material material;
            double thick = check.Thick(books.Workbooks["M"], out material, tempMaterials, errors);

            EdgeBanding ebw1 = check.EBW1(books.Workbooks["E"], tempEdgebandings);
            EdgeBanding ebw2 = check.EBW2(books.Workbooks["E"], tempEdgebandings);
            EdgeBanding ebl1 = check.EBL1(books.Workbooks["E"], tempEdgebandings);
            EdgeBanding ebl2 = check.EBL2(books.Workbooks["E"], tempEdgebandings);

            int basepoint = check.BasePoint();
            MachinePoint machinePoint = check.MachinePoint();

            double xRotation = check.XRotation();
            double yRotation = check.YRotation();
            double zRotation = check.ZRotation();

            bool isDraw3d;
            string layname3d = check.Layname3d(out isDraw3d);
            string layname2d = partRange[0, 36].Text;

            if (width <= 0 || length <= 0 || thick <= 0)
            {
                return errors;
            }

            check.IsMaterialFitPartLengthAndWidth(length, width, material, errors);

            //TODO:tokens

            bool isEQPart = check.IsEQPart();
            if (isEQPart)
            {
                List<double[]> origins = check.Positions(qty, thick, product.Width);

                foreach (var d in origins)
                {
                    Part part = new Part(partName, 1, width, length, thick, material.Name,
                        ebw1.Name, ebw2.Name, ebl1.Name, ebl2.Name,
                        "", "", "",
                        basepoint, machinePoint.MP,
                        d[0], d[1], d[2], xRotation, yRotation, zRotation,
                        layname3d, layname2d,
                        product);
                    parts.Add(part);
                }
            }
            else
            {
                double xPos = check.XPosition();
                double yPos = check.YPosition();
                double zPos = check.ZPosition();
                Part part = new Part(partName, qty, width, length, thick, material.Name,
                    ebw1.Name, ebw2.Name, ebl1.Name, ebl2.Name,
                    "", "", "",
                    basepoint, machinePoint.MP,
                    xPos, yPos, zPos, xRotation, yRotation, zRotation,
                    layname3d, layname2d,
                    product);

                parts.Add(part);
            }

            return errors;
        }
示例#17
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="streamToWriteOutputTo"></param>
        /// <param name="sheets"></param>
        /// <param name="format"></param>
        public static void ExportList(Stream streamToWriteOutputTo, List <ExportPart> sheets, FileFormat format)
        {
            sheets = FixSheetNames(sheets);
            IWorkbookSet workBook = Factory.GetWorkbookSet();
            int          maxRows  = (format == FileFormat.OpenXMLWorkbook || format == FileFormat.OpenXMLWorkbookMacroEnabled) ? 1048575 : 65536;

            string    tempSheetName = null;
            IWorkbook iBook         = workBook.Workbooks.Add();

            try {
                // There's allways 1 sheet when creating a new book.
                // If a new sheet has the same name, an exception will be thrown.
                // So, this sheet is renamed, and in the end, deleted. (we can't delete it here since there must be at least 1 sheet in a book)
                if (iBook.Sheets["Sheet1"] != null)
                {
                    tempSheetName = Guid.NewGuid().ToString().Substring(0, 31);
                    iBook.Sheets["Sheet1"].Name = tempSheetName;
                }
            } catch {
            }
            IColors   colorPalett = iBook.Colors;
            Hashtable colorHash   = new Hashtable();

            if (format == FileFormat.OpenXMLWorkbook)
            {
                colorPalett = null;
                colorHash   = null;
            }
            int colorPalettIndex = 0;

            if (colorPalett != null)
            {
                colorPalett[colorPalettIndex++] = Color.Black;
                colorPalett[colorPalettIndex++] = Color.White;
                colorHash[Color.Black.ToArgb()] = null;
                colorHash[Color.White.ToArgb()] = null;
            }
            List <DataValidationInfo> dataValidationInfos = new List <DataValidationInfo>();

            foreach (ExportPart part in sheets)
            {
                IWorksheet iSheet = iBook.Worksheets.Add();
                iSheet.Name = part.SheetName;
                IRange cells = iSheet.Cells;

                int cellIndex     = 0;
                int rowIndex      = AddExcelHeaders(cells, part, colorHash, colorPalett, ref colorPalettIndex);
                int startRowIndex = rowIndex;
                cellIndex = 0;
                int       sheetCount     = 1;
                int       totalItemIndex = 0;
                Hashtable rowSpans       = new Hashtable();
                if (part.DataValidationLists.Count > 0)
                {
                    foreach (ExportPart.DataValidationList dvl in part.DataValidationLists)
                    {
                        dataValidationInfos.Add(new DataValidationInfo()
                        {
                            DVL = dvl, Sheet = iSheet, StartRow = rowIndex
                        });
                    }
                }
                foreach (CellDataList data in part.Data)
                {
                    foreach (CellData value in data)
                    {
                        if (rowSpans.CheckIfRowSpanAndDecrease(cellIndex))
                        {
                            continue;
                        }
                        if (value.URL != null)
                        {
                            cells[rowIndex, cellIndex].Hyperlinks.Add(cells[rowIndex, cellIndex], value.URL, "", value.URLTip, value.Value);
                        }
                        if (value.TextFormat)
                        {
                            cells[rowIndex, cellIndex].NumberFormat = "@";
                        }
                        if (!string.IsNullOrEmpty(value.NumberFormat))
                        {
                            cells[rowIndex, cellIndex].NumberFormat = value.NumberFormat;
                        }
                        if (value.TextDirectionDegrees > 0)
                        {
                            cells[rowIndex, cellIndex].Orientation = value.TextDirectionDegrees;
                        }
                        if (value.BackgroundColor != Color.Transparent)
                        {
                            if (colorHash != null && !colorHash.ContainsKey(value.BackgroundColor.ToArgb()) && colorPalettIndex < 56)
                            {
                                colorHash[value.BackgroundColor.ToArgb()] = null;
                                colorPalett[colorPalettIndex++]           = MakePalettValid(value.BackgroundColor);
                            }
                            cells[rowIndex, cellIndex].Interior.Color = value.BackgroundColor;
                            //value.Value = "Color.FromArgb( {0}, {1}, {2} )".FillBlanks( value.BackgroundColor.R, value.BackgroundColor.G, value.BackgroundColor.B );
                        }
                        if (value.FontColor != SystemColors.WindowText)
                        {
                            if (colorHash != null && !colorHash.ContainsKey(value.FontColor.ToArgb()) && colorPalettIndex < 56)
                            {
                                colorHash[value.FontColor.ToArgb()] = null;
                                colorPalett[colorPalettIndex++]     = MakePalettValid(value.FontColor);
                            }
                            cells[rowIndex, cellIndex].Font.Color = value.FontColor;
                        }
                        if (value.Bold)
                        {
                            cells[rowIndex, cellIndex].Font.Bold = value.Bold;
                        }
                        if (value.Underline.HasValue)
                        {
                            cells[rowIndex, cellIndex].Font.Underline = value.Underline.Value ? UnderlineStyle.Single : UnderlineStyle.None;
                        }
                        if (value.Pattern)
                        {
                            cells[rowIndex, cellIndex].Interior.Pattern      = Pattern.Down;
                            cells[rowIndex, cellIndex].Interior.PatternColor = Color.White;
                        }
                        if (value.PatternColor != Color.Empty)
                        {
                            if (colorHash != null && !colorHash.ContainsKey(value.PatternColor.ToArgb()) && colorPalettIndex < 56)
                            {
                                colorHash[value.PatternColor.ToArgb()] = null;
                                colorPalett[colorPalettIndex++]        = MakePalettValid(value.PatternColor);
                            }
                            cells[rowIndex, cellIndex].Interior.PatternColor = value.PatternColor;
                        }

                        cells[rowIndex, cellIndex].WrapText = value.WrapText;

                        if (value.LeftBorder)
                        {
                            cells[rowIndex, cellIndex].Borders[BordersIndex.EdgeLeft].Weight = BorderWeight.Thin;
                        }
                        if (value.LeftBorderColor != Color.Transparent)
                        {
                            if (colorHash != null && !colorHash.ContainsKey(value.LeftBorderColor.ToArgb()) && colorPalettIndex < 56)
                            {
                                colorHash[value.LeftBorderColor.ToArgb()] = null;
                                colorPalett[colorPalettIndex++]           = MakePalettValid(value.LeftBorderColor);
                            }
                            cells[rowIndex, cellIndex].Borders[BordersIndex.EdgeLeft].Color = value.LeftBorderColor;
                        }
                        if (value.RightBorder)
                        {
                            cells[rowIndex, cellIndex].Borders[BordersIndex.EdgeRight].Weight = BorderWeight.Thin;
                        }
                        if (value.RightBorderColor != Color.Transparent)
                        {
                            if (colorHash != null && !colorHash.ContainsKey(value.RightBorderColor.ToArgb()) && colorPalettIndex < 56)
                            {
                                colorHash[value.RightBorderColor.ToArgb()] = null;
                                colorPalett[colorPalettIndex++]            = MakePalettValid(value.RightBorderColor);
                            }
                            cells[rowIndex, cellIndex].Borders[BordersIndex.EdgeRight].Color = value.RightBorderColor;
                        }
                        if (value.TopBorder)
                        {
                            cells[rowIndex, cellIndex].Borders[BordersIndex.EdgeTop].Weight = BorderWeight.Thin;
                        }
                        if (value.TopBorderColor != Color.Transparent)
                        {
                            if (colorHash != null && !colorHash.ContainsKey(value.TopBorderColor.ToArgb()) && colorPalettIndex < 56)
                            {
                                colorHash[value.TopBorderColor.ToArgb()] = null;
                                colorPalett[colorPalettIndex++]          = MakePalettValid(value.TopBorderColor);
                            }
                            cells[rowIndex, cellIndex].Borders[BordersIndex.EdgeTop].Color = value.TopBorderColor;
                        }
                        if (value.BottomBorder)
                        {
                            cells[rowIndex, cellIndex].Borders[BordersIndex.EdgeBottom].Weight = BorderWeight.Thin;
                        }
                        if (value.BottomBorderColor != Color.Transparent)
                        {
                            if (colorHash != null && !colorHash.ContainsKey(value.BottomBorderColor.ToArgb()) && colorPalettIndex < 56)
                            {
                                colorHash[value.BottomBorderColor.ToArgb()] = null;
                                colorPalett[colorPalettIndex++]             = MakePalettValid(value.BottomBorderColor);
                            }
                            cells[rowIndex, cellIndex].Borders[BordersIndex.EdgeBottom].Color = value.BottomBorderColor;
                        }
                        if (!string.IsNullOrEmpty(value.Comment))
                        {
                            cells[rowIndex, cellIndex].AddComment(value.Comment).Visible = false;
                        }
                        if (value.CenterInCell)
                        {
                            cells[rowIndex, cellIndex].Style.HorizontalAlignment = HAlign.Center;
                            cells[rowIndex, cellIndex].Style.VerticalAlignment   = VAlign.Center;
                        }
                        if (value.VerticalAlignment != VAlign.Bottom)
                        {
                            cells[rowIndex, cellIndex].Style.VerticalAlignment = value.VerticalAlignment;
                        }
                        if (value.HorizontalAlignment != HAlign.General)
                        {
                            cells[rowIndex, cellIndex].Style.HorizontalAlignment = value.HorizontalAlignment;
                        }
                        if (value.FontSize > 0f)
                        {
                            cells[rowIndex, cellIndex].Font.Size = value.FontSize;
                        }
                        try {
                            cells[rowIndex, cellIndex].Value = value.Value;
                        } catch (ArgumentException ex) {
                            cells[rowIndex, cellIndex].Value     = "Error setting value with " + (value.Value != null ? value.Value.Length + " characters" : "null") + ": " + ex.Message + " Try exporting as text instead...";
                            cells[rowIndex, cellIndex].Font.Bold = true;
                        } catch (Exception ex) {
                            cells[rowIndex, cellIndex].Value     = "Error setting value: " + ex.Message;
                            cells[rowIndex, cellIndex].Font.Bold = true;
                        }
                        //cells[ rowIndex, cellIndex ].ShrinkToFit = true; // krymper bara texten...
                        if (value.ColumnWidth > 0)
                        {
                            cells[rowIndex, cellIndex].ColumnWidth = value.ColumnWidth;
                        }
                        if (value.RowHeight > 0)
                        {
                            cells[rowIndex, cellIndex].RowHeight = value.RowHeight;
                        }
                        if (value.ColSpan > 1)
                        {
                            cells[rowIndex, cellIndex, rowIndex, cellIndex + value.ColSpan - 1].Merge();
                            //cells[ rowIndex, cellIndex + value.ColSpan - 1 ].Merge();
                        }
                        if (value.RowSpan > 1)
                        {
                            cells[rowIndex, cellIndex, rowIndex + value.RowSpan - 1, cellIndex].Merge();
                            rowSpans[cellIndex] = value.RowSpan;
                        }
                        if (value.ColSpan > 1)
                        {
                            cellIndex += value.ColSpan;
                        }
                        else
                        {
                            cellIndex++;
                        }
                    }
                    cellIndex = 0;
                    rowIndex++;

                    //if( rowIndex >= ExportPart.MaxNumberOfExcelSheetRows && (part.Data.Count > (totalItemIndex + 1)) ) {
                    if (rowIndex >= maxRows && (part.Data.Count > (totalItemIndex + 1)))
                    {
                        if (part.AutoFitColumnWidths)
                        {
                            try {
                                string colRef = "A:" + (char)('A' + (part.Headers.Count - 1));
                                cells[colRef].AutoFitColumns();
                                //cells[ 0, 1, rowIndex, 1 ].Rows.AutoFit();
                                //cells[ 0, 1, rowIndex, 1 ].AutoFit();
                                //double oldWidth = cells[ 0, 1, rowIndex, 1 ].ColumnWidth;
                                //try {
                                //    cells[ 0, 1, rowIndex, 1 ].ColumnWidth += 10;
                                //} catch {
                                //    cells[ 0, 1, rowIndex, 1 ].ColumnWidth = oldWidth;
                                //}
                            } catch {
                            }
                        }
                        sheetCount++;
                        iSheet      = iBook.Worksheets.Add();
                        iSheet.Name = part.SheetName + " (" + sheetCount + ")";
                        cells       = iSheet.Cells;
                        rowIndex    = AddExcelHeaders(cells, part, colorHash, colorPalett, ref colorPalettIndex);
                        rowSpans    = new Hashtable();
                        if (part.DataValidationLists.Count > 0)
                        {
                            foreach (ExportPart.DataValidationList dvl in part.DataValidationLists)
                            {
                                dataValidationInfos.Add(new DataValidationInfo()
                                {
                                    DVL = dvl, Sheet = iSheet, StartRow = rowIndex
                                });
                            }
                        }
                    }
                    totalItemIndex++;
                }
                if (part.AutoFitColumnWidths)
                {
                    try {
                        string colRef = "A:" + (char)('A' + (part.Headers.Count - 1));
                        cells[colRef].AutoFitColumns();
                    } catch {
                    }
                }
            }
            AddDataValidationLists(iBook, sheets);
            foreach (DataValidationInfo dvi in dataValidationInfos)
            {
                foreach (int dvlColumn in dvi.DVL.Columns)
                {
                    if (dvi.DVL.Values.Count > 0)
                    {
                        dvi.Sheet.Cells[dvi.StartRow, dvlColumn, maxRows, dvlColumn].Validation.Add(ValidationType.List, ValidationAlertStyle.Warning, ValidationOperator.Equal, "=" + dvi.DVL.Name, null);
                    }
                }
            }
            if (tempSheetName != null)
            {
                try {
                    if (iBook.Sheets[tempSheetName] != null)
                    {
                        iBook.Sheets[tempSheetName].Delete();
                    }
                } catch {
                }
            }
            if (iBook.Sheets.Count > 0)
            {
                iBook.Sheets[0].Select();
            }
            iBook.SaveToStream(streamToWriteOutputTo, format);
            streamToWriteOutputTo.Flush();
            iBook = null;
            workBook.Dispose();
            workBook = null;
            GC.Collect(3);
        }
示例#18
0
        public List <ModelError> GetPartsFromOneLine(IRange partRange, IProduct product, List <Part> parts, IWorkbookSet books, List <Material> tempMaterials, List <EdgeBanding> tempEdgebandings)
        {
            List <ModelError> errors = new List <ModelError>();

            PartChecker check = new PartChecker(partRange, errors);

            string partName = check.PartName();
            int    qty      = check.Qty();

            if (qty <= 0)
            {
                return(errors);
            }

            double width  = check.Width();
            double length = check.Length();

            Material material;
            double   thick = check.Thick(books.Workbooks["M"], out material, tempMaterials, errors);

            EdgeBanding ebw1 = check.EBW1(books.Workbooks["E"], tempEdgebandings);
            EdgeBanding ebw2 = check.EBW2(books.Workbooks["E"], tempEdgebandings);
            EdgeBanding ebl1 = check.EBL1(books.Workbooks["E"], tempEdgebandings);
            EdgeBanding ebl2 = check.EBL2(books.Workbooks["E"], tempEdgebandings);

            int          basepoint    = check.BasePoint();
            MachinePoint machinePoint = check.MachinePoint();

            double xRotation = check.XRotation();
            double yRotation = check.YRotation();
            double zRotation = check.ZRotation();

            bool   isDraw3d;
            string layname3d = check.Layname3d(out isDraw3d);
            string layname2d = partRange[0, 36].Text;

            if (width <= 0 || length <= 0 || thick <= 0)
            {
                return(errors);
            }

            check.IsMaterialFitPartLengthAndWidth(length, width, material, errors);

            //TODO:tokens

            bool isEQPart = check.IsEQPart();

            if (isEQPart)
            {
                List <double[]> origins = check.Positions(qty, thick, product.Width);

                foreach (var d in origins)
                {
                    Part part = new Part(partName, 1, width, length, thick, material.Name,
                                         ebw1.Name, ebw2.Name, ebl1.Name, ebl2.Name,
                                         "", "", "",
                                         basepoint, machinePoint.MP,
                                         d[0], d[1], d[2], xRotation, yRotation, zRotation,
                                         layname3d, layname2d,
                                         product);
                    parts.Add(part);
                }
            }
            else
            {
                double xPos = check.XPosition();
                double yPos = check.YPosition();
                double zPos = check.ZPosition();
                Part   part = new Part(partName, qty, width, length, thick, material.Name,
                                       ebw1.Name, ebw2.Name, ebl1.Name, ebl2.Name,
                                       "", "", "",
                                       basepoint, machinePoint.MP,
                                       xPos, yPos, zPos, xRotation, yRotation, zRotation,
                                       layname3d, layname2d,
                                       product);

                parts.Add(part);
            }

            return(errors);
        }
示例#19
0
 internal MyCommandManager(IWorkbookSet workbookSet)
     : base(workbookSet)
 {
 }