iT邦幫忙

2

C# Excel設定雙實線外框線

c#
Ming 2022-09-06 14:29:581389 瀏覽
  • 分享至 

  • xImage

https://ithelp.ithome.com.tw/upload/images/20220906/20152275pzrCBas36v.png
請問如何在匯出EXCEL時,在指定範圍的外框線設定為雙實線
目前寫出來只能把範圍內所有線改為雙實線而無法達成範圍最外框設定為雙實線

        Excel._Workbook excelBook;
        Excel._Worksheet excelSheet;
        Excel.Range excelRange;
        
        有匯入Excel參考寫程式
        excelRange = excelApplication.get_Range(string.Format("B{0}", ExcelCountY + 4), string.Format("F{0}", ExcelCountY + ExcelCountX + 4));
        excelRange.Borders.LineStyle = Excel.XlLineStyle.xlDouble;
        excelRange.BorderAround2();
Ming iT邦新手 5 級 ‧ 2022-09-07 10:51:26 檢舉
最後用這段程式解決
excelRange.BorderAround(Excel.XlLineStyle.xlDouble, Excel.XlBorderWeight.xlMedium, Excel.XlColorIndex.xlColorIndexAutomatic, 0x000000);
謝謝各位大大
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

2 個回答

1
allenlwh
iT邦高手 1 級 ‧ 2022-09-06 14:56:38
CellRange range1 = worksheet.Range["B8:F13"];
range1.Borders.SetAllBorders(Color.Green, BorderLineStyle.Double);
allenlwh iT邦高手 1 級 ‧ 2022-09-06 15:00:28 檢舉
1
海綿寶寶
iT邦大神 1 級 ‧ 2022-09-06 15:59:59

綜合樓上和這篇
得到程式碼如下

CellRange range = worksheet.Range["C3:K11"];
range.Borders.LineStyle = xlDouble;
range.BorderAround2();

不妨試試看可不可用

Ming iT邦新手 5 級 ‧ 2022-09-06 16:16:45 檢舉

目前嘗試中間D:J的儲存格還是會有格線,無法做到只在外框有格線的樣式

allenlwh iT邦高手 1 級 ‧ 2022-09-06 16:41:22 檢舉

先把範圍內的儲存格格線設為None

Range("A2:K100").Borders.LineStyle = xlNone
Ming iT邦新手 5 級 ‧ 2022-09-07 08:35:00 檢舉

好像沒辦法

我要發表回答

立即登入回答