简体   繁体   English

如何使用动态数据创建PDFsharp表?

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

I am populating a table in PDFsharp to display chart legend data. 我在PDFsharp中填充表格以显示图表图例数据。 I have 14 objects in my list and only 2 are being displayed, and the colors of their rectangles are identical. 我的列表中有14个对象,只显示了2个,矩形颜色相同。 They each have a unique color to use. 它们每种都有独特的颜色可供使用。 How can I get all of them to display correctly? 如何让所有这些都正确显示?

   //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);

                };
            };

List of objects 对象列表 PIC

This is the result I am currently getting 这是我目前得到的结果 图片

I guess the color string of Data[1] contains a blank (blue has two digits only). 我猜数据[1]的颜色字符串包含一个空白(蓝色只有两位数)。 Maybe this causes the match to fail and the line is skipped. 也许这会导致匹配失败并跳过该行。

As a hack you can try regex.Match(colorStr.Replace(" ", "")); 作为一个黑客你可以尝试regex.Match(colorStr.Replace(" ", "")); . Better modify the regular expression to allow spaces. 更好地修改正则表达式以允许空格。

You do not show the color string for Savannah. 你没有显示萨凡纳的颜色字符串。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM