上面是我Excel底板
請問我合併儲存格和字的顏色怎麼寫呢?
和空格顏色
HSSFWorkbook workbook;
//讀取專案內中的ZZZ.xls 的excel 檔案
using (FileStream file = new FileStream(AppDomain.CurrentDomain.BaseDirectory + "ZZZ.xls", FileMode.Open, FileAccess.Read))
{
workbook = new HSSFWorkbook(file);
}
//讀取Sheet1 工作表
var sheet = workbook.GetSheet("工作表");
for (int row = 0; row <= sheet.LastRowNum; row++)
{
if (sheet.GetRow(row) != null) //null is when the row only contains empty cells
{
foreach (var c in sheet.GetRow(row).Cells)
{
//如果是數字型 就要取 NumericCellValue 這屬性的值
if(c.CellType==CellType.NUMERIC)
Response.Write(c.NumericCellValue.ToString("#"));
//如果是字串型 就要取 StringCellValue 這屬性的值
if(c.CellType==CellType.STRING)
Response.Write(c.StringCellValue);
//每個欄中間加上逗點
Response.Write(",");
//合併儲存格
CellRangeAddress region = new CellRangeAddress(0, 0, 1, 8);
sheet.AddMergedRegion(region);
}
Response.Write("<br />");