簡體   English   中英

win32com 線型 Excel

[英]win32com LineStyle Excel

在此處輸入圖像描述

幸運的是我找到了這一面: https ://www.linuxtut.com/en/150745ae0cc17cb5c866/

(有很多 Linetypes 定義了 Excel Enum XlLineStyle)

(xlContinuous    =  1
xlDashDot       =  4
xlDashDotDot    =  5
xlSlantDashDot  = 13
xlDash          = -4115
xldot           = -4118
xlDouble        = -4119
xlLineStyleNone = -4142)

我嘗試運行,除了 +/- 100.000 次設置線,因為我認為任何地方都應該是這個 [index] 數字,以便將這條線也放在我的圖片中,但他們警告......為什么不呢?

我該如何設置這條線? 為什么在如此巨大的負數牧場中有一些線索引,而不僅僅是 1、2、3...? 我怎樣才能發現像“數字”這樣的東西呢?

為什么這甚至可能,要在特定位置發送應用程序數據,我想更深入一點,我在哪里可以了解更多信息?

(1)您在 linestyle 枚舉中找不到虛線的介質,因為沒有。 繪制為邊框的線是lineStyleWeight的組合。 lineStyle 為 xlDash,表中值為 03 的重量為xlThin ,值為 08 的重量為xlMedium

(2)要弄清楚如何在 VBA 中設置這樣的東西,請使用宏記錄器,它會顯示在設置邊框時設置了 lineStyle、Weight(和顏色)。

(3)有很多頁面描述了所有常量,例如查看評論中鏈接到的@FaneDuru。 它們也可以在 Microsoft 本身找到: https ://docs.microsoft.com/en-us/office/vba/api/excel.xllinestyle 和https://docs.microsoft.com/en-us/office/vba /api/excel.xlborderweight 似乎有人在 linuxTut 頁面上將它們翻譯成 Python 常量。

(4)不要問為什么枚舉不是連續值。 我特別假設帶有負數的常數更多地用於一個目的。 只是永遠不要直接使用值,總是使用定義的常量。

(5)您可以假設沒有定義常量的數值可以工作,但結果有點不可預測。 沒有常數的值不太可能導致“新”事物(例如不同的邊框樣式)。

正如您在下表中看到的,並非所有組合都給出不同的邊框。 將權重設置為xlHairline將忽略 lineStyle。 將其設置為xlThick也將忽略 lineStyle, xlDouble除外。 另一方面, xlDouble重不是 xlThick 時,將忽略xlThick

Sub border()
    With ThisWorkbook.Sheets(1)
        With .Range("A1:J18")
            .Clear
            .Interior.Color = vbWhite
        End With
        
        Dim lStyles(), lWeights(), lStyleNames(), lWeightNames
        lStyles() = Array(xlContinuous, xlDash, xlDashDot, xlDashDotDot, xlDot, xlDouble, xlLineStyleNone, xlSlantDashDot)
        lStyleNames() = Array("xlContinuous", "xlDash", "xlDashDot", "xlDashDotDot", "xlDot", "xlDouble", "xlLineStyleNone", "xlSlantDashDot")
        lWeights = Array(xlHairline, xlThin, xlMedium, xlThick)
        lWeightNames = Array("xlHairline", "xlThin", "xlMedium", "xlThick")
 
        Dim x As Long, y As Long
        For x = LBound(lStyles) To UBound(lStyles)
            Dim row As Long
            row = x * 2 + 3
            .Cells(row, 1) = lStyleNames(x) & vbLf & "(" & lStyles(x) & ")"
            
            For y = LBound(lWeights) To UBound(lWeights)
                Dim col As Long
                col = y * 2 + 3
                If x = 1 Then .Cells(1, col) = lWeightNames(y) & vbLf & "(" & lWeights(y) & ")"
                With .Cells(row, col).Borders
                    .LineStyle = lStyles(x)
                    .Weight = lWeights(y)
                End With
            Next
        Next
    End With
End Sub

在此處輸入圖像描述

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM