コード例 #1
0
        public static void PrintObject(object sh, MetaPage page, MetaObject obj, int dpix,
                                       int dpiy, SortedList rows, SortedList columns,
                                       string FontName, int FontSize, int rowinit, double Precision)
        {
            const int xlHAlignCenter = -4108;
            const int xlHAlignLeft   = -4131;
            const int xlHAlignRight  = -4152;
            string    atext;
            int       arow;
            int       acolumn;
            bool      isanumber;
            FontStyle astyle;
            Color     acolor;
            bool      isadate;

            string topstring  = ((double)obj.Top / Precision).ToString("0000000000");
            string leftstring = ((double)obj.Left / Precision).ToString("0000000000");

            arow    = rows.IndexOfKey(topstring) + 1 + rowinit;
            acolumn = columns.IndexOfKey(leftstring) + 1;
            if (acolumn < 1)
            {
                acolumn = 1;
            }
            if (arow < 1)
            {
                arow = 1;
            }
            object cells = sh.GetType().InvokeMember("Cells",
                                                     System.Reflection.BindingFlags.GetProperty, null, sh, null);

            object[] param2 = new object[2];
            param2[0] = arow;
            param2[1] = acolumn;
            object[] param1 = new object[1];
            object   cell   = cells.GetType().InvokeMember("Item",
                                                           System.Reflection.BindingFlags.GetProperty, null, cells, param2);

            switch (obj.MetaType)
            {
            case MetaObjectType.Text:
                MetaObjectText objt = (MetaObjectText)obj;
                atext = page.GetText(objt);

                // If it's a number
                bool assigned = false;
                isanumber = DoubleUtil.IsNumeric(atext, System.Globalization.NumberStyles.Any);
                if (isanumber)
                {
                    param1[0] = System.Convert.ToDouble(atext);
                    cell.GetType().InvokeMember("Value",
                                                System.Reflection.BindingFlags.SetProperty,
                                                null, cell, param1);
                    assigned = true;
                }
                else
                {
                    DateTime mydate;
                    isadate = DateUtil.IsDateTime(atext, out mydate);
                    if (isadate)
                    {
                        param1[0] = mydate;
                        cell.GetType().InvokeMember("Value",
                                                    System.Reflection.BindingFlags.SetProperty,
                                                    null, cell, param1);
                        assigned = true;
                    }
                    else
                    if (atext.Length > 0)
                    {
                        if (atext[0] == '=')
                        {
                            atext = "'" + atext;
                        }
                        param1[0] = atext;
                        cell.GetType().InvokeMember("Value",
                                                    System.Reflection.BindingFlags.SetProperty,
                                                    null, cell, param1);
                        assigned = true;
                    }
                }
                if (assigned)
                {
                    object shfont = cell.GetType().InvokeMember("Font",
                                                                System.Reflection.BindingFlags.GetProperty,
                                                                null, cell, null);
                    string nfontname = page.GetWFontNameText(objt);
                    if (FontName != nfontname)
                    {
                        param1[0] = nfontname;
                        shfont.GetType().InvokeMember("Name",
                                                      System.Reflection.BindingFlags.SetProperty,
                                                      null, shfont, param1);
                    }
                    if (objt.FontSize != FontSize)
                    {
                        param1[0] = objt.FontSize;
                        shfont.GetType().InvokeMember("Size",
                                                      System.Reflection.BindingFlags.SetProperty,
                                                      null, shfont, param1);
                    }
                    acolor = GraphicUtils.ColorFromInteger(objt.FontColor);
                    if (acolor.ToArgb() != Color.Black.ToArgb())
                    {
                        param1[0] = objt.FontColor;
                        shfont.GetType().InvokeMember("Color",
                                                      System.Reflection.BindingFlags.SetProperty,
                                                      null, shfont, param1);
                    }
                    astyle = GraphicUtils.FontStyleFromInteger(objt.FontStyle);
                    if ((astyle & FontStyle.Italic) > 0)
                    {
                        param1[0] = true;
                        shfont.GetType().InvokeMember("Italic",
                                                      System.Reflection.BindingFlags.SetProperty,
                                                      null, shfont, param1);
                    }
                    if ((astyle & FontStyle.Bold) > 0)
                    {
                        param1[0] = true;
                        shfont.GetType().InvokeMember("Bold",
                                                      System.Reflection.BindingFlags.SetProperty,
                                                      null, shfont, param1);
                    }
                    if ((astyle & FontStyle.Underline) > 0)
                    {
                        param1[0] = true;
                        shfont.GetType().InvokeMember("Underline",
                                                      System.Reflection.BindingFlags.SetProperty,
                                                      null, shfont, param1);
                    }
                    if ((astyle & FontStyle.Strikeout) > 0)
                    {
                        param1[0] = true;
                        shfont.GetType().InvokeMember("Strikethrough",
                                                      System.Reflection.BindingFlags.SetProperty,
                                                      null, shfont, param1);
                    }
                    // Font rotation not possible
                    if ((objt.Alignment & MetaFile.AlignmentFlags_AlignHCenter) > 0)
                    {
                        param1[0] = xlHAlignCenter;
                        cell.GetType().InvokeMember("HorizontalAlignment",
                                                    System.Reflection.BindingFlags.SetProperty,
                                                    null, cell, param1);
                    }
                    // Multiline not supported
                    //    if (obj.AlignMent AND AlignmentFlags_SingleLine)=0 then
                    //     sh.Cells.item[arow,acolumn].Multiline:=true;
                    if ((objt.Alignment & MetaFile.AlignmentFlags_AlignLeft) > 0)
                    {
                        if (isanumber)
                        {
                            param1[0] = xlHAlignLeft;
                            cell.GetType().InvokeMember("HorizontalAlignment",
                                                        System.Reflection.BindingFlags.SetProperty,
                                                        null, cell, param1);
                        }
                    }
                    if ((objt.Alignment & MetaFile.AlignmentFlags_AlignRight) > 0)
                    {
                        if (!isanumber)
                        {
                            param1[0] = xlHAlignRight;
                            cell.GetType().InvokeMember("HorizontalAlignment",
                                                        System.Reflection.BindingFlags.SetProperty,
                                                        null, cell, param1);
                        }
                    }
                    // Word wrap not supported
                    //    if obj.WordWrap then
                    //     sh.Cells.item[arow,acolumn].WordWrap:=True;
                    //    if Not obj.CutText then
                    //     aalign:=aalign or DT_NOCLIP;
                    //    if obj.RightToLeft then
                    //     aalign:=aalign or DT_RTLREADING;
                    // In office 97, not supported
                    //    if Not obj.Transparent then
                    //     sh.Cells.Item[arow,acolumn].Color:=CLXColorToVCLColor(obj.BackColor);
                }
                break;
            }
        }