// Reference the owc11 (COM component) in the project)
Owc11.spreadsheetclass xlsheet = new owc11.spreadsheetclass ();
// Merge Cells
Xlsheet. get_range (xlsheet. cells [], xlsheet. cells []). set_mergecells (true );
Xlsheet. activesheet. cells [] = "Primary Account ";
// Bold font
Xlsheet. get_range (xlsheet. cells [], xlsheet. cells []). Font. set_bold (true );
// Align the cell text horizontally.
Xlsheet. get_range (xlsheet. cells [1, 1], xlsheet. cells [1, 14]). set_horizontalalignment (owc11.xlhalign. xlhaligncenter );
// Set the font size
Xlsheet. get_range (xlsheet. cells [], xlsheet. cells []). Font. set_size (14 );
// Set the column width
Xlsheet. get_range (xlsheet. cells [1, 3], xlsheet. cells [1, 3]). set_columnwidth (50 );
// draw a border line
xlsheet. get_range (xlsheet. cells [1, 1], xlsheet. cells [10, 15]). borders. set_linestyle (owc11.xllinestyle. xlcontinuous);
// Write data (this can be generated by DS as needed)
For (int row = 2; row <10; row ++) // note that when writing data, you must write data from the first row without row "0" in Excel.
{
For (INT I = 0; I <15; I ++)
{
Xlsheet. activesheet. cells [row, I + 1] = 123.456;
}
}
Try
{
// Format the number as the amount (the value in the cell to be formatted must be numeric)
Xlsheet. get_range (xlsheet. cells [2, 1], xlsheet. cells [10, 15]). set_numberformat ("¥ #, #0.00 ");
Xlsheet. Export ("D: // exporttoexcel // testowc.xls", owc11.sheetexportactionenum. ssexportactionnone, owc11.sheetexportformat. ssexportxmlspreadsheet );
Response. Write ("Export OK ");
}
Catch
{
}
Other functions need to be further understood and learned from each other!