一个会的不多的人

一个会的不多的人

大家好,今天接着写我们的通用方法总结分享。

下面是今天要分享的通用方法:

(1)通过输入信息,返回合并的单元格内容。这个方法比较好用,适合在有合并的单元格时候使用。

        /// <summary>

        /// 返回合并单元格的左上角内容

        /// </summary>

        /// <returns></returns>

        public string MergeCellContents(Microsoft.Office.Interop.Excel.Range ismeerge, Microsoft.Office.Interop.Excel.Worksheet WSheet, int rows,int cell)

        {

            string content = "";

            if (ismeerge.MergeCells == true)

            {

                if (ismeerge.MergeArea.Row == rows && ismeerge.MergeArea.Column == cell)

                {

                    content = ismeerge.Text;

                }

                else

                {

                    content = ((Microsoft.Office.Interop.Excel.Range)WSheet.Cells[ismeerge.MergeArea.Row, ismeerge.MergeArea.Column]).Text;

                }

            }

            return content;

        }

(2)这个通用方法为获取sheet页中的所有图片,将图片和单元格的行index值存放在一个字典中。

/// <summary>

        /// 获取每个sheet页,所有行和图片的集合

        /// </summary>

        /// <param name="worksheet"></param>

        /// <returns></returns>

        public Dictionary<int, Aspose.Cells.Drawing.Picture> EachSheetImage(Aspose.Cells.Worksheet worksheet)

        {

            Dictionary<int, Aspose.Cells.Drawing.Picture> eachlist = new Dictionary<int, Aspose.Cells.Drawing.Picture>();

            Aspose.Cells.License l = new Aspose.Cells.License();

            l.SetLicense(System.Windows.Forms.Application.StartupPath + @"\Aspose.License.lic");//破解许可证

            Aspose.Cells.Workbook workbook = new Aspose.Cells.Workbook(uiTextBox1.Text);//读取表格                                                                                  

            Aspose.Cells.Drawing.PictureCollection picture = worksheet.Pictures;//读取图片

            for(int i=0;i< picture.Count;i++)

            {

                int x = picture[i].LowerRightRow;

                eachlist.Add(x, picture[i]);

            }

            return eachlist;

        }

(3)这个通用方法为Ug二次开发,获取选中尺寸线类型,这只是一部分类型,其他类型下集再讲。

  string getmeasure(Part workPart, int type, int subtype, Tag selectTag)//获取尺寸线类型

    {

        string measure = " ";

        string uni = "mm";

        if (type == 26 && subtype == 5)  //线性尺寸类型

        {

            NXOpen.Annotations.Dimension Dimension1 = (NXOpen.Annotations.Dimension)NXObjectManager.Get(selectTag);

            NXOpen.Annotations.LinearDimensionBuilder linearDimensionBuilder1;

            linearDimensionBuilder1 = workPart.Dimensions.CreateLinearDimensionBuilder(Dimension1);

            if (linearDimensionBuilder1.Style.UnitsStyle.DimensionLinearUnits == NXOpen.Annotations.DimensionUnit.Inches)

            {

                uni = "un";

            }

            string[] measures = linearDimensionBuilder1.Style.DimensionStyle.GetOverriddenDimensionText();

            measure = measures[0] + "$" + uni;

        }

        if (type == 26 && subtype == 1)  //线性尺寸类型

        {

            NXOpen.Annotations.Dimension Dimension1 = (NXOpen.Annotations.Dimension)NXObjectManager.Get(selectTag);

            NXOpen.Annotations.LinearDimensionBuilder linearDimensionBuilder1;

            linearDimensionBuilder1 = workPart.Dimensions.CreateLinearDimensionBuilder(Dimension1);

            if (linearDimensionBuilder1.Style.UnitsStyle.DimensionLinearUnits == NXOpen.Annotations.DimensionUnit.Inches)

            {

                uni = "un";

            }

            string[] measures = linearDimensionBuilder1.Style.DimensionStyle.GetOverriddenDimensionText();

            measure = measures[0] + "$" + uni;

        }

        if (type == 26 && subtype == 3)  //线性尺寸类型

        {

            NXOpen.Annotations.Dimension Dimension1 = (NXOpen.Annotations.Dimension)NXObjectManager.Get(selectTag);

            NXOpen.Annotations.LinearDimensionBuilder linearDimensionBuilder1;

            linearDimensionBuilder1 = workPart.Dimensions.CreateLinearDimensionBuilder(Dimension1);

            if (linearDimensionBuilder1.Style.UnitsStyle.DimensionLinearUnits == NXOpen.Annotations.DimensionUnit.Inches)

            {

                uni = "un";

            }

            string[] measures = linearDimensionBuilder1.Style.DimensionStyle.GetOverriddenDimensionText();

            measure = measures[0] + "$" + uni;

        }

}

今天要介绍的就是这些,我们下篇文章再见。

07-26 09:38