C# 没有单间距字体的字符串对齐

C# 没有单间距字体的字符串对齐,c#,excel,string,vsto,C#,Excel,String,Vsto,我想要在excel中的右键单击菜单中跨多行对齐的字符串。添加的右键单击菜单如下所示: CommandBar contextMenu = Globals.ThisWorkbook.Application.CommandBars["List Range Popup"]; CommandBarPopup subMenu = (CommandBarPopup)contextMenu.Controls.Add(Type: MsoControlType.msoControlPopup, Before:

我想要在excel中的右键单击菜单中跨多行对齐的字符串。添加的右键单击菜单如下所示:

 CommandBar contextMenu = Globals.ThisWorkbook.Application.CommandBars["List Range Popup"];
 CommandBarPopup subMenu = (CommandBarPopup)contextMenu.Controls.Add(Type: MsoControlType.msoControlPopup, Before: 1, Temporary: true);
 subMenu.Caption = "Assumptions Drill Down";
然后,我迭代数据库结果并添加到下一行的子菜单中 当前结果如下(使用字符串填充):

由于字符空间不均匀(非等距字体),因此列不对齐。我曾尝试执行以下操作以获取字符串的像素大小,然后转换回所需的字符串填充整数,但我无法使其正常工作:

    private static double GetStringSize(string stringText)
    {
        Bitmap b = new Bitmap(1, 1);
        Graphics g = Graphics.FromImage(b);
        SizeF size = g.MeasureString(stringText,
            new System.Drawing.Font("Calibri", 10, FontStyle.Regular, GraphicsUnit.Point));
        return size.Width;
    }
  • 有没有办法将右击字体设置为等距字体(我不这么认为)
  • 如果我做不到(1),我如何确保每列中的间距是均匀的?例如,将“iiiii”与“qqq”的用户均匀对齐 ?