0

enter image description here

How do i fit values in those horizontally splitted cells ? I am cloning each row dynamically. The values being populated currently is a merge field as i was using this approach but i couldn't make the report dynamic with it. Any help would be appreciated.

Aman Adhikari
  • 3,240
  • 3
  • 22
  • 32

1 Answers1

1

Well, you cannot input two values in a single cell in MS Excel. I think You may achieve your task by merging/ un-merging some cells and input values into relevant cells accordingly. See the sample code below for your reference, it covers and design some part of your attached table/matrix. Please refer to it and you may write your own code (via Aspose.Cells APIs) to accomplish your task accordingly:

  var workbook = new Workbook();
        var worksheet = workbook.Worksheets[0];

        //Input header value to B1 cell (later we will merge it: B1:C1 --> B1
        worksheet.Cells[0, 1].PutValue("header2");

        //Input value to B2 cell that would be merged with B3 to become B2.
        worksheet.Cells[1, 1].PutValue(1);

        //Input value to C2 cell.
        worksheet.Cells[1, 2].PutValue(2);

        //Input value to C3 cell.
        worksheet.Cells[2, 2].PutValue(3);

        //Set row heights for 2nd and third rows for the cells accordingly.
        worksheet.Cells.SetRowHeight(1, 25);
        worksheet.Cells.SetRowHeight(2, 25);

        //Merging cells.
        //Merge B1:C1 --> B1
        worksheet.Cells.Merge(0, 1, 1, 2);
        //Merge B2:B3 --> B2
        worksheet.Cells.Merge(1, 1, 2, 1);


        //Formatting cells and ranges.
        //Creating a range that spans over the all data cells of a worksheet
        var range = worksheet.Cells.CreateRange("B1", "C3");
        //Create a Style object.
        Style colstyle = workbook.CreateStyle();
        colstyle.Borders[BorderType.LeftBorder].LineStyle = CellBorderType.Thin;
        colstyle.Borders[BorderType.RightBorder].LineStyle = CellBorderType.Thin;
        colstyle.Borders[BorderType.TopBorder].LineStyle = CellBorderType.Thin;
        colstyle.Borders[BorderType.BottomBorder].LineStyle = CellBorderType.Thin;
        colstyle.HorizontalAlignment = TextAlignmentType.Center;
        StyleFlag flag = new StyleFlag();
        flag.Borders = true;
        flag.HorizontalAlignment = true;
        //Apply the style to the range
        range.ApplyStyle(colstyle, flag);


        workbook.Save("e:\\test2\\output__mergedcells.xlsx");

See the screen shot of the output Excel file taken in Ms Excel for your reference: http://prntscr.com/8rbc0i

I am a developer/evangelist at Aspose.

Amjad Sahi
  • 1,813
  • 1
  • 10
  • 15
  • Thanks for the quick response. Does this implies for WORDS as well ? – Aman Adhikari Oct 15 '15 at 11:28
  • What do you mean, could you elaborate? Well, if you are talking about input words (text), well, you may write statement/sentence obviously in a cell (separated by space(s) etc.) and you can wrap text as well. – Amjad Sahi Oct 15 '15 at 17:50
  • The solution we had is for excel file does this works for .docx(word) file as well ? – Aman Adhikari Oct 16 '15 at 07:06
  • I think you should try to use Aspose.Words APIs to accomplish the task for word documents. Aspose.Cells is a spreadsheet management library used to create, render, manipulate or print Ms Excel file formats (XLS, XLSX etc.). – Amjad Sahi Oct 16 '15 at 17:58
  • I am weak explainer so sorry but i actually use Aspose.words only. sorry for all the mistyping can you have save idea on ASPOSE.words ?? – Aman Adhikari Oct 18 '15 at 16:14
  • Hi Aman, I see you have already posted this query in Aspose.Words forum. I would suggest you please follow [that thread](http://www.aspose.com/community/forums/thread/663070.aspx) for further proceedings. I work with Aspose as Developer Evangelist. – Awais Hafeez Oct 20 '15 at 03:55