public static void Run()
        {
            // ExStart:1
            CellsApi   cellsApi   = new CellsApi(Common.APP_KEY, Common.APP_SID, Common.BASEPATH);
            StorageApi storageApi = new StorageApi(Common.APP_KEY, Common.APP_SID, Common.BASEPATH);

            String fileName        = "Sample_Test_Book.xls";
            String sheetName       = "Sheet1";
            int    mergedCellIndex = 0;
            String storage         = "";
            String folder          = "";

            try
            {
                // Upload source file to aspose cloud storage
                storageApi.PutCreate(fileName, "", "", System.IO.File.ReadAllBytes(Common.GetDataDir() + fileName));

                // Invoke Aspose.Cells Cloud SDK API to get merged cells from worksheet
                MergedCellResponse apiResponse = cellsApi.GetWorkSheetMergedCell(fileName, sheetName, mergedCellIndex, storage, folder);

                if (apiResponse != null && apiResponse.Status.Equals("OK"))
                {
                    MergedCell mergedCell = apiResponse.MergedCell;
                    Console.WriteLine("Merge Start Column :: " + mergedCell.StartColumn);
                    Console.WriteLine("Merge End Column :: " + mergedCell.EndColumn);
                    Console.ReadKey();
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine("error:" + ex.Message + "\n" + ex.StackTrace);
            }
            // ExEnd:1
        }
Ejemplo n.º 2
0
        public int CreateHeader(out IList <string> formats)
        {
            int width        = Tree.Roots.Sum(x => x.CalculateLeaesCount());
            int height       = Tree.Roots.Max(x => x.MaxDepth);
            var allRetangles = Tree.CalculateRetangles();

            formats = Tree.Roots.SelectMany(x => x.CalculateLeaves()).Select(x => x.Format).ToList();
            //创建原子单元格

            for (int i = 0; i < height; i++)
            {
                for (int j = 0; j < width; j++)
                {
                    var cell = sheet.Cells[i + 1, j + 1];


                    var retangle = allRetangles.FirstOrDefault(x => x.RetanglePosition.X == j && x.RetanglePosition.Y == i);
                    if (retangle != null)
                    {
                        cell.Value = retangle.Title;
                        cell.AutoFitColumns();
                    }
                }
            }

            //  计算合并
            foreach (var retangle in allRetangles)
            {
                var mergedCellDefine = new MergedCell(retangle);
                var mergedCell       = sheet.Cells[
                    mergedCellDefine.StartRow, mergedCellDefine.StartColumn,
                    mergedCellDefine.EndRow, mergedCellDefine.EndColumn];
                mergedCell.Merge = true;
                mergedCell.Style.HorizontalAlignment = OfficeOpenXml.Style.ExcelHorizontalAlignment.Center;
                mergedCell.Style.VerticalAlignment   = OfficeOpenXml.Style.ExcelVerticalAlignment.Center;

                mergedCell.Style.Border.BorderAround(OfficeOpenXml.Style.ExcelBorderStyle.Medium);
                mergedCell.Style.Fill.PatternType = OfficeOpenXml.Style.ExcelFillStyle.Solid;
                mergedCell.Style.Fill.BackgroundColor.SetColor(Color.LightYellow);
                mergedCell.Value = retangle.Title;
            }
            return(height);
        }