Passing a C# variable to Aspose Cells .Net

How do I pass a variable from C# to Aspose Cells so I can use it to populate a cell in Excel. For example I have a account name I stored in String acName = null; and in my sql I populate acName with data from the database. I want to pass acName to the Excel spreadsheet Im creating using Aspose Cells. Thanks

Hi,


Thanks for your query.

Well, I am not sure about your requirements, could you elaborate it more. For your information, Aspose.Cells is a spreadsheet management library that does not provide any UI. If you need to populate cells with data (that may come from your interface or variables in your application), please see the documents for your reference:

And if you need to import data from some data source, Well, you have to first import data (you may use your own ADO.NET code (you may use your own SQL query based on your requirements too.) to first fetch it and then fill it to some container like DataTable or Arrays/ List), then you may use Aspose.Cells APIs to fill it worksheet cells, see the document on data importing options provided by Aspose.Cells for your complete reference:

Let us know if we can be of any further help.

Thank you.


Let me elaborate. I have text box where a user will enter a name and that name is saved in my asp .net as a variable called inputName. When I create my excel spreadsheet I import my data to my data table and use Aspose,Cells API to fill in the worksheet. But I also want to include the values of the variable inputName into cell A1 of the worksheet. How do I pass the value of inputName to location A1 of the worksheet. Thanks

Hi,


Please see the documents (I have shared URLs already) in my previous post for your complete reference on how to insert data into the cells and how to import data from a variety of data sources. To insert a value (whether the value comes from a variable), see the simple sample code below for your reference:
e.g
Sample code:

//Create a new Workbook
Workbook workbook = new Workbook();
//Get the first worksheet (default sheet in the new workbook)
Worksheet worksheet = workbook.Worksheets[0];
//Get the cells collection in the sheet
Cells cells = worksheet.Cells;
//Get the A1 cell
Cell cell = cells[“A1”];
//Your variable object where you store input name in it.
string userName = “your inputName”;
//insert it into the cell
cell.PutValue(userName);

Hope, this helps a bit.

Thank you.

Amjad,

I followed your example and I got my project to work.

Thank you,
Phil

Hi Phil,

It is good to know that you are up & running again. Please feel free to contact us back in case you need our further assistance with Aspose APIs.