public ActionResult ValidateSpreadsheet(object Spreadsheet)
        {
            IWorkbook myWorkBook = SpreadsheetExtension.GetCurrentDocument("Spreadsheet");
            int       test       = Convert.ToInt32(myWorkBook.Worksheets[0].Cells["B3"].Value.NumericValue);

            return(Json(test));
        }
Beispiel #2
0
        public ActionResult Custom(Guid?entityId)
        {
            SpreadSheetModel spreadSheetModel = new SpreadSheetModel();

            if (entityId != null && entityId.HasValue)
            {
                IOrganizationService             orgSerivce = CreateOrganizationService();
                CrmServiceContext                context    = new CrmServiceContext(orgSerivce);
                new_project_initiative_valuation valuation  = null;
                Annotation annotation = GetAnnotation(context, entityId, out valuation);
                spreadSheetModel.IsReadOnly = valuation != null && valuation.StatusCodeEnum == new_project_initiative_valuation_StatusCode.Neaktivnye;
                spreadSheetModel.Body       = SpreadsheetExtension.GetCurrentDocument("SpreadSheetEditor").SaveDocument(DocumentFormat.Xlsx);
                string documentBody = Convert.ToBase64String(spreadSheetModel.Body);
                if (annotation == null)
                {
                    orgSerivce.Create(new Annotation()
                    {
                        ObjectId       = new EntityReference(new_project_initiative_valuation.EntityLogicalName, entityId.Value),
                        ObjectTypeCode = new_project_initiative_valuation.EntityLogicalName,
                        MimeType       = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
                        FileName       = "[Project Calculation].xlsx",
                        DocumentBody   = documentBody
                    });
                }
                else
                {
                    annotation.DocumentBody = documentBody;
                    context.UpdateObject(annotation);
                    context.SaveChanges();
                }
            }
            return(PartialView("SpreadSheetPartial", spreadSheetModel));
        }
        public ActionResult SpreadsheetCustomPartial(string diagramName)
        {
            IWorkbook wbook = SpreadsheetExtension.GetCurrentDocument("Spreadsheet");

            switch (diagramName)
            {
            case "PieChart":
                DiagramCreationHelper.CreatePieChart(wbook);
                break;

            case "BarChart":
                DiagramCreationHelper.CreateBarChart(wbook);
                break;

            case "ColumnChart":
                DiagramCreationHelper.CreateColumnChart(wbook);
                break;

            case "ComplexChart":
                DiagramCreationHelper.CreateComplexChart(wbook);
                break;

            case "DoughnutChart":
                DiagramCreationHelper.CreateDoughnutChart(wbook);
                break;

            case "Pie3dChart":
                DiagramCreationHelper.CreatePie3dChart(wbook);
                break;

            case "ScatterChart":
                DiagramCreationHelper.CreateScatterChart(wbook);
                break;

            case "StockChart":
                DiagramCreationHelper.CreateStockChart(wbook);
                break;

            case "BubbleChart":
                DiagramCreationHelper.CreateBubbleChart(wbook);
                break;
            }

            return(PartialView("_SpreadsheetPartial"));
        }
        public ActionResult CustomAction(string customCommand)
        {
            IWorkbook workbook  = SpreadsheetExtension.GetCurrentDocument("Spreadsheet");
            Worksheet worksheet = workbook.Worksheets[0];

            switch (customCommand)
            {
            case "applyFormatting":
                CellRange  priceRange      = worksheet.Range["C2:C15"];
                Formatting rangeFormatting = priceRange.BeginUpdateFormatting();
                rangeFormatting.Font.Color           = Color.SandyBrown;
                rangeFormatting.Font.FontStyle       = SpreadsheetFontStyle.Bold;
                rangeFormatting.Fill.BackgroundColor = Color.PaleGoldenrod;
                rangeFormatting.NumberFormat         = "$0.0#";

                rangeFormatting.Alignment.Vertical   = SpreadsheetVerticalAlignment.Center;
                rangeFormatting.Alignment.Horizontal = SpreadsheetHorizontalAlignment.Center;
                priceRange.EndUpdateFormatting(rangeFormatting);
                break;

            case "insertLink":
                worksheet.Columns["G"].WidthInPixels = 180;
                Cell cell1 = worksheet.Cells["G4"];
                cell1.Fill.BackgroundColor = Color.WhiteSmoke;
                worksheet.Hyperlinks.Add(cell1, "https://documentation.devexpress.com/OfficeFileAPI/14912/Spreadsheet-Document-API", true, "Spreadsheet Document API");
                break;

            case "drawBorders":
                CellRange tableRange = worksheet.Range["A2:E16"];
                tableRange.Borders.SetAllBorders(Color.RosyBrown, BorderLineStyle.Hair);
                break;

            case "showTotal":
                Cell cell2 = worksheet.Cells["E16"];
                cell2.Formula = "=SUBTOTAL(9,E2:E15)";
                Cell cell3 = worksheet.Cells["A16"];
                cell3.Formula = "SUBTOTAL(103,A2:A15)";
                Cell cell4 = worksheet.Cells["D16"];
                cell4.Value = "Total amount";
                break;
            }
            return(SpreadsheetExtension.GetCustomActionResult("Spreadsheet"));
        }
        Stream GetPdfStream()
        {
            MemoryStream ms       = new MemoryStream();
            IWorkbook    workBook = SpreadsheetExtension.GetCurrentDocument("Spreadsheet");

            workBook.SaveDocument(ms, DocumentFormat.Xlsm);
            ms.Position = 0;
            Workbook docServer = new Workbook();

            docServer.LoadDocument(ms, DocumentFormat.Xlsm);
            ms.Position = 0;
            PrintableComponentLink link = new PrintableComponentLink(new PrintingSystem());

            link.Component = docServer;
            link.ExportToPdf(ms);
            ms.Position = 0;

            return(ms);
        }