コード例 #1
0
ファイル: HomeController.cs プロジェクト: stringly/BlueDeck
        public IActionResult DownloadOrganizationChart(int id)
        {
            OrgChartGenerator gen      = new OrgChartGenerator(unitOfWork.Components.GetOrgChartComponentsWithMembersNoMarkup(id));
            string            fileName = $"{unitOfWork.Components.Get(id).Name} Organization Chart {DateTime.Now.ToString("MM'-'dd'-'yy")}.docx";

            return(File(gen.Generate(), "application/vnd.openxmlformats-officedocument.wordprocessingml.document", fileName));
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: wangGuangXu/OrgChart
        static void Main(string[] args)
        {
            OrgChartOption defaultOption = new OrgChartOption
            {
                BoxFillColor     = ColorTranslator.FromHtml("#A7E7FC"),
                BoxBorderColor   = ColorTranslator.FromHtml("#A7E7FC"),
                ConnectLineColor = ColorTranslator.FromHtml("#424242")
            };

            //微软雅黑

            OrgChartOption option = new OrgChartOption()
            {
                BoxFillColor     = defaultOption.BoxFillColor,
                BoxBorderColor   = defaultOption.BoxBorderColor,
                ConnectLineColor = defaultOption.ConnectLineColor,
                FontSize         = 12,
                HorizontalSpace  = 10,
                VerticalSpace    = 30,
                BoxHeight        = 45,
                BoxWidth         = 110,
                FontName         = "宋体"
                                   //UseMinBoxWidthWhenHasOnlyOne = true,
                                   //MinBoxWidth = 80
            };

            OrgChartGenerator orgChartGenerator = new OrgChartGenerator(GetOrgChartNodes(), option)
            {
                DefaultOption = defaultOption
            };

            string filePath = "皮庄组朱姓祖先.png";

            using (FileStream fs = File.Create(filePath))
            {
                MemoryStream ms = orgChartGenerator.Generate();
                ms.WriteTo(fs);
                fs.Flush();
            }

            try
            {
                Process.Start(filePath);
            }
            catch
            {
                if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
                {
                    filePath = filePath.Replace("&", "^&");
                    Process.Start(new ProcessStartInfo("cmd", $"/c start {filePath}")
                    {
                        CreateNoWindow = true
                    });
                }
                else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
                {
                    Process.Start("xdg-open", filePath);
                }
                else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
                {
                    Process.Start("open", filePath);
                }
                else
                {
                    throw;
                }
            }
        }