Click here to Skip to main content
15,893,622 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am writing program in C# to copy excel sheet data into email with the original format of the cells. (Text Format Color and cell border as table - not formula)

This is what I coded in C#.
xlApp = new Excel.Application()
xlWorkBook = xlApp.Workbooks.Open("C:\\Projects\\Data\\Rev.xls", 0, true, 5, "", "", true, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "\t", false, false, 0, true, 1, 0);
xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(3);

range = xlWorkSheet.UsedRange;

for (rCnt = 3; rCnt <= 13; rCnt++)
{
for (cCnt = 5; cCnt <= 6; cCnt++)
{
exceldata[ai] = "XX";
if ((range.Cells[rCnt, cCnt] as Excel.Range).Value2 != null)
{
exceldata[ai] = (range.Cells[rCnt, cCnt] as Excel.Range).Text;
str += exceldata[ai];
str += "\n";
}
ai++;
}
}
I did it with range.Value2 method of excelsheet object. But than I had to create html source code file and had to set all cells value into it. But I lost original format of the cells. I think I can do it better than this with Range.FormatConditions method. But don't know how to implement it. Any help please?
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900