簡體   English   中英

如何使用動態數據創建PDFsharp表?

[英]How to create a PDFsharp table with dynamic data?

我在PDFsharp中填充表格以顯示圖表圖例數據。 我的列表中有14個對象,只顯示了2個,矩形顏色相同。 它們每種都有獨特的顏色可供使用。 如何讓所有這些都正確顯示?

   //Draw the table Row Borders
            xGrap.DrawRectangle(XPens.DarkSeaGreen, XBrushes.DarkSeaGreen, snoColumn); //Use different Color for Colum
            xGrap.DrawRectangle(XPens.DarkSeaGreen, XBrushes.DarkSeaGreen, snoStudentName);

            //Writting Table Header Text
            textformater.DrawString(" Color", tableheader, XBrushes.Black, snoColumn);
            textformater.DrawString(" Subdivision Name", tableheader, XBrushes.Black, snoStudentName);

            foreach (var item in data)
            {
                string colorStr = item.Color;

                Regex regex = new Regex(@"rgb\((?<r>\d{1,3}),(?<g>\d{1,3}),(?<b>\d{1,3})\)");
                Match match = regex.Match(colorStr);
                if (match.Success)
                {
                    int r = int.Parse(match.Groups["r"].Value);
                    int g = int.Parse(match.Groups["g"].Value);
                    int b = int.Parse(match.Groups["b"].Value);

                    y = y + 30;
                    XRect snoColumnVal = new XRect(35, y, 60, 25);
                    XRect snoStudentNameVal = new XRect(100, y, 250, 25);

                    var brush = new XSolidBrush(XColor.FromArgb(r, g, b));
                    xGrap.DrawRectangle(brush, snoColumnVal);
                    textformater.DrawString(item.Name, bodyfont, XBrushes.Black, snoStudentNameVal);

                };
            };

對象列表 PIC

這是我目前得到的結果 圖片

我猜數據[1]的顏色字符串包含一個空白(藍色只有兩位數)。 也許這會導致匹配失敗並跳過該行。

作為一個黑客你可以嘗試regex.Match(colorStr.Replace(" ", "")); 更好地修改正則表達式以允許空格。

你沒有顯示薩凡納的顏色字符串。

暫無
暫無

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

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