Append cell text without deleting existing text into cell

Hi,


Is it possible to append the text in cell which already contain some data without loosing the old text?

Ex: sheet.Cells[0,1] has “Hello” and i want to append “Aspose”
So sheet.Cells[0,1] should contain “Hello Aspose” as a result.



Thanks in advance.

Hi there,

Thank you for considering Aspose.

You can always use String concatenation operator (+) for your requirement. Please check the below provided source code and attached output spreadsheet for you reference.

C#


//Instantiating a Workbook object
Workbook workbook = new Workbook();
//Obtaining the reference of the first worksheet by
//passing its sheet index
Worksheet worksheet = workbook.Worksheets[0];
//Insert some text in a cell
worksheet.Cells[0, 1].PutValue(“Hello”);
//Reterieve the inserted text
string value = worksheet.Cells[0, 1].StringValue;
//Append another text to existing text
value += " Aspose";
//Set the new modified text to the cell
worksheet.Cells[0, 1].PutValue(value);
//Save workbook
workbook.Save(myDir + “output.xlsx”);

Thanks Babar,


It works :slight_smile:

Hi Aspose team,

Similarly like above, Can we add a Text in a cell which already has some number value (coming as data from database).
For ex:
if a cell contains 785887 , can we make it like this 785887SOS.

Thanks in advance.

@SakethDodda,

I guess you are using Java. See the sample lines of code to accomplish your task for your reference.
e.g.
Sample code:

........
Cell cell = worksheet.getCells().get("A1");
cell.putValue(cell.getStringValue() + "SOS"); 
......

Hope, this helps a bit.

A post was split to a new topic: Set different formats for the subtotal rows separately