Пример #1
0
 private async Task <Aspose.Cells.Drawing.Picture> StyleImageCheck(Aspose.Cells.Drawing.Picture pic)
 {
     pic.Height = 20;
     pic.Width  = 20;
     pic.Top    = 5;
     pic.Left   = 40;
     return(await Task.FromResult(pic));
 }
        public static void Run()
        {
            // ExStart:1
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

            // Create directory if it is not already present.
            bool IsExists = System.IO.Directory.Exists(dataDir);

            if (!IsExists)
            {
                System.IO.Directory.CreateDirectory(dataDir);
            }

            // Instantiate a new workbook
            Workbook workbook = new Workbook();

            // Get the first worksheet
            Worksheet worksheet = workbook.Worksheets[0];

            // Insert a string value to a cell
            worksheet.Cells["C2"].PutValue("Image Hyperlink");

            // Set the 4th row height
            worksheet.Cells.SetRowHeight(3, 100);

            // Set the C column width
            worksheet.Cells.SetColumnWidth(2, 21);

            // Add a picture to the C4 cell
            int index = worksheet.Pictures.Add(3, 2, 4, 3, dataDir + "aspose-logo.jpg");

            // Get the picture object
            Aspose.Cells.Drawing.Picture pic = worksheet.Pictures[index];

            // Set the placement type
            pic.Placement = PlacementType.FreeFloating;

            // Add an image hyperlink
            Aspose.Cells.Hyperlink hlink = pic.AddHyperlink("http:// Www.aspose.com/");

            // Specify the screen tip
            hlink.ScreenTip = "Click to go to Aspose site";
            dataDir         = dataDir + "ImageHyperlink.out.xls";
            // Save the Excel file
            workbook.Save(dataDir);
            // ExEnd:1
            Console.WriteLine("\nProcess completed successfully.\nFile saved at " + dataDir);
        }
Пример #3
0
        public static void Main(string[] args)
        {
            // The path to the documents directory.
            string dataDir = Path.GetFullPath("../../../Data/");

            // Create directory if it is not already present.
            bool IsExists = System.IO.Directory.Exists(dataDir);

            if (!IsExists)
            {
                System.IO.Directory.CreateDirectory(dataDir);
            }

            //Instantiate a new workbook
            Workbook workbook = new Workbook();

            //Get the first worksheet
            Worksheet worksheet = workbook.Worksheets[0];

            //Insert a string value to a cell
            worksheet.Cells["C2"].PutValue("Image Hyperlink");

            //Set the 4th row height
            worksheet.Cells.SetRowHeight(3, 100);

            //Set the C column width
            worksheet.Cells.SetColumnWidth(2, 21);

            //Add a picture to the C4 cell
            int index = worksheet.Pictures.Add(3, 2, 4, 3, dataDir + "aspose-logo.jpg");

            //Get the picture object
            Aspose.Cells.Drawing.Picture pic = worksheet.Pictures[index];

            //Set the placement type
            pic.Placement = PlacementType.FreeFloating;

            //Add an image hyperlink
            Aspose.Cells.Hyperlink hlink = pic.AddHyperlink("http://www.aspose.com/");

            //Specify the screen tip
            hlink.ScreenTip = "Click to go to Aspose site";

            //Save the Excel file
            workbook.Save(dataDir + "ImageHyperlink.xls");
        }
        public static void Run()
        {
            //Source directory
            string sourceDir = RunExamples.Get_SourceDirectory();

            //Output directory
            string outputDir = RunExamples.Get_OutputDirectory();

            // Instantiate a new workbook
            Workbook workbook = new Workbook();

            // Get the first worksheet
            Worksheet worksheet = workbook.Worksheets[0];

            // Insert a string value to a cell
            worksheet.Cells["C2"].PutValue("Image Hyperlink");

            // Set the 4th row height
            worksheet.Cells.SetRowHeight(3, 100);

            // Set the C column width
            worksheet.Cells.SetColumnWidth(2, 21);

            // Add a picture to the C4 cell
            int index = worksheet.Pictures.Add(3, 2, 4, 3, sourceDir + "sampleAddImageHyperlinks.jpg");

            // Get the picture object
            Aspose.Cells.Drawing.Picture pic = worksheet.Pictures[index];

            // Set the placement type
            pic.Placement = PlacementType.FreeFloating;

            // Add an image hyperlink
            Aspose.Cells.Hyperlink hlink = pic.AddHyperlink("https://www.aspose.com");

            // Specify the screen tip
            hlink.ScreenTip = "Click to go to Aspose site";

            // Save the Excel file
            workbook.Save(outputDir + "outputAddImageHyperlinks.xlsx");

            Console.WriteLine("AddImageHyperlinks executed successfully.\r\n");
        }
Пример #5
0
        public async Task <ActionResult> ExportExcelDetailAspose([FromQuery] string articleCateID, string articleID, int checkExport)
        {
            var data = await _articleService.GetArticleByID(articleCateID, articleID.ToInt());

            var path = Path.Combine(_webHostEnvironment.ContentRootPath, "Resources\\Template\\Article\\ArticleDetailTemplate.xlsx");
            WorkbookDesigner designer = new WorkbookDesigner();

            designer.Workbook = new Workbook(path);

            Cell      cell  = designer.Workbook.Worksheets[0].Cells["A1"];
            Worksheet ws    = designer.Workbook.Worksheets[0];
            Cells     cells = ws.Cells;

            designer.SetDataSource("result", data);
            designer.Process();

            Style style = designer.Workbook.CreateStyle();

            style.IsTextWrapped       = true;
            style.VerticalAlignment   = TextAlignmentType.Center;
            style.HorizontalAlignment = TextAlignmentType.Center;
            style.Borders[BorderType.BottomBorder].LineStyle = CellBorderType.Thin;
            style.Borders[BorderType.TopBorder].LineStyle    = CellBorderType.Thin;
            style.Borders[BorderType.LeftBorder].LineStyle   = CellBorderType.Thin;
            style.Borders[BorderType.RightBorder].LineStyle  = CellBorderType.Thin;

            StyleFlag flg = new StyleFlag();

            flg.All = true;

            int index = 2;

            ws.Cells["A" + (index)].PutValue(data.Article_Cate_ID);
            ws.Cells["B" + (index)].PutValue(data.Article_Name);
            ws.Cells["C" + (index)].PutValue(data.Content);
            ws.Cells["E" + (index)].PutValue(data.Update_By);
            ws.Cells["F" + (index)].PutValue(data.Update_Time.ToString());

            string folderImage = _webHostEnvironment.WebRootPath + "\\uploaded\\images\\article\\";
            string folderVideo = _webHostEnvironment.WebRootPath + "\\uploaded\\video\\article\\";

            if (!string.IsNullOrEmpty(data.FileImages))
            {
                string[] listImage = data.FileImages.Split(";");
                foreach (var image in listImage)
                {
                    if (image != "")
                    {
                        Aspose.Cells.Drawing.Picture pic = ws.Pictures[ws.Pictures.Add(index - 1, 6, folderImage + image)];
                        pic = await StyleImageExcel(pic);

                        ws.Cells.SetRowHeight(index - 1, 45);

                        index++;
                    }
                }
            }
            int index1 = 2;

            if (!string.IsNullOrEmpty(data.FileVideos))
            {
                string[] listVideo = data.FileVideos.Split(";");
                foreach (var video in listVideo)
                {
                    if (video != "")
                    {
                        Aspose.Cells.Drawing.Picture pic = ws.Pictures[ws.Pictures.Add(index1 - 1, 7, folderVideo + "video.jpg")];
                        pic = await StyleImageExcel(pic);

                        ws.Cells.SetRowHeight(index1 - 1, 45);

                        index1++;
                    }
                }
            }
            int index3 = index >= index1 ? index : index1;

            if (!string.IsNullOrEmpty(data.FileImages) || !string.IsNullOrEmpty(data.FileVideos))
            {
                // Merge column not image, video
                int[] number = { 0, 1, 2, 3, 4, 5 };
                foreach (var item in number)
                {
                    cells.Merge(1, item, index3 - 2, 1);
                }
                // Set style
                for (int i = 1; i < index3 - 1; i++)
                {
                    string[] text = { "A", "B", "C", "D", "E", "F", "G", "H" };
                    foreach (var item in text)
                    {
                        ws.Cells[item + (i + 1)].SetStyle(style, flg);
                    }
                }
            }
            string file = _dropzoneService.CheckTrueFalse(data.Status);

            Aspose.Cells.Drawing.Picture picStatus = ws.Pictures[ws.Pictures.Add(1, 3, file)];
            picStatus = await StyleImageCheck(picStatus);

            picStatus.Top = (index3 - 2 == 0 ? 1 : index3 - 2) * 20;

            MemoryStream stream = new MemoryStream();

            string fileKind      = "";
            string fileExtension = "";

            if (checkExport == 1)
            {
                designer.Workbook.Save(stream, SaveFormat.Xlsx);
                fileKind      = "application/xlsx";
                fileExtension = ".xlsx";
            }
            if (checkExport == 2)
            {
                // custom size ( width: in, height: in )
                ws.PageSetup.FitToPagesTall = 0;
                ws.PageSetup.SetHeader(0, "&D &T");
                ws.PageSetup.SetHeader(1, "&B Article");
                ws.PageSetup.SetFooter(0, "&B SYSTEM BY MINH HIEU");
                ws.PageSetup.SetFooter(2, "&P/&N");
                ws.PageSetup.PrintQuality = 1200;
                designer.Workbook.Save(stream, SaveFormat.Pdf);
                fileKind      = "application/pdf";
                fileExtension = ".pdf";
            }

            byte[] result = stream.ToArray();

            return(File(result, fileKind, "Article_Detail_" + DateTime.Now.ToString("dd_MM_yyyy_HH_mm_ss") + fileExtension));
        }
Пример #6
0
        public async Task <ActionResult> ExportExcelListAspose([FromQuery] PaginationParams param, string text, int checkExport, string articleCateID, string articleName, int checkSearch)
        {
            PageListUtility <Article_Dto> data;

            if (checkSearch == 1)
            {
                data = await _articleService.GetArticleWithPaginations(param, text, false);
            }
            else
            {
                data = await _articleService.SearchArticleWithPaginations(param, articleCateID, articleName, false);
            }
            var path = Path.Combine(_webHostEnvironment.ContentRootPath, "Resources\\Template\\Article\\ArticleListTemplate.xlsx");
            WorkbookDesigner designer = new WorkbookDesigner();

            designer.Workbook = new Workbook(path);

            Cell      cell = designer.Workbook.Worksheets[0].Cells["A1"];
            Worksheet ws   = designer.Workbook.Worksheets[0];

            designer.SetDataSource("result", data.Result);
            designer.Process();

            Style style = ws.Cells["F2"].GetStyle();

            style.Custom = "dd/MM/yyyy hh:mm:ss";

            for (int i = 1; i <= data.Result.Count; i++)
            {
                ws.Cells["F" + (i + 1)].SetStyle(style);
            }

            int index = 1;

            foreach (var item in data.Result)
            {
                if (item.Content.Length > 70)
                {
                    ws.AutoFitRow(index);
                }
                else
                {
                    ws.Cells.SetRowHeight(index, 22.5);
                }
                string file = _dropzoneService.CheckTrueFalse(item.Status);
                Aspose.Cells.Drawing.Picture pic = ws.Pictures[ws.Pictures.Add(index, 3, file)];
                pic = await StyleImageCheck(pic);

                index++;
            }

            MemoryStream stream = new MemoryStream();

            string fileKind      = "";
            string fileExtension = "";

            if (checkExport == 1)
            {
                designer.Workbook.Save(stream, SaveFormat.Xlsx);
                fileKind      = "application/xlsx";
                fileExtension = ".xlsx";
            }
            if (checkExport == 2)
            {
                // custom size ( width: in, height: in )
                ws.PageSetup.FitToPagesTall = 0;
                ws.PageSetup.SetHeader(0, "&D &T");
                ws.PageSetup.SetHeader(1, "&B Article");
                ws.PageSetup.SetFooter(0, "&B SYSTEM BY MINH HIEU");
                ws.PageSetup.SetFooter(2, "&P/&N");
                ws.PageSetup.PrintQuality = 1200;
                designer.Workbook.Save(stream, SaveFormat.Pdf);
                fileKind      = "application/pdf";
                fileExtension = ".pdf";
            }

            byte[] result = stream.ToArray();

            return(File(result, fileKind, "Article_List_" + DateTime.Now.ToString("dd_MM_yyyy_HH_mm_ss") + fileExtension));
        }