We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Issue in converting the Introp code to expose code

Hi,

I am new in aspose. getting issue to convert the below lin of code in aspose. please provide the help on the below line of code.

Excel._Workbook workBook =

null;

Excel.Worksheet workSheet =

null;

Excel.Range cellRange =

null;

int priceCode = 0;

try

{

//Open new work book

workBook = ExcelApp.Workbooks.Add(Type.Missing);

// Get Reference to work sheet which is sheet 1

workSheet =(Excel.Worksheet) workBook.Worksheets[1];

workSheet.Application.ReferenceStyle = Excel.XlReferenceStyle.xlA1;

//Jyotsna Adding Headers

StringCollection headers =

new StringCollection();

headers.Add(

"Survey Date(MM/DD/YYYY)");

headers.Add(

"Country ID");

headers.Add(

"Country Name");

headers.Add(

"City ID");

headers.Add(

"Item Id");

headers.Add(

"Item Name");

headers.Add(

"Currency");

headers.Add(

"Low Price");

headers.Add(

"Medium Price");

headers.Add(

"High Price");

headers.Add(

"Average");

int asciiCode=65;//Code for 'A'

string cellPosition=string.Empty;

int row = 1;

for (int headersCount = 0; headersCount < headers.Count; headersCount++)

{

Char cellValue = Convert.ToChar(asciiCode);

cellPosition = cellValue + row.ToString();

((Excel.Range)workSheet.get_Range(cellPosition, cellPosition)).Value2 = headers[headersCount];

asciiCode++;

}

thanks in advance for support

Hi,

Thanks for your posting and using Aspose.Cells.

Please
see the following equivalent code for your needs. I have also attached
the output Excel file generated by the code for your reference.

Let us know if you still have any question, we will look into it and help you asap.

C#


List<string> headers = new List<string>();

headers.Add(“Survey Date(MM/DD/YYYY)”);

headers.Add(“Country ID”);

headers.Add(“Country Name”);

headers.Add(“City ID”);

headers.Add(“Item Id”);

headers.Add(“Item Name”);

headers.Add(“Currency”);

headers.Add(“Low Price”);

headers.Add(“Medium Price”);

headers.Add(“High Price”);

headers.Add(“Average”);


//Create workbook

Workbook workbook = new Workbook();


//Access first worksheet

Worksheet worksheet = workbook.Worksheets[0];


//Add values of headers in cells A1, A2, A3… so on.

for (int headersCount = 0; headersCount < headers.Count; headersCount++)

{

string cellPosition = “A” + (headersCount + 1);


worksheet.Cells[cellPosition].PutValue(headers[headersCount]);

}


//Save workbook

workbook.Save(“output.xlsx”);