C#:通用方法总结—第4集

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

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

(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;

}

}

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

相关推荐
a***560634 分钟前
Windows上安装Go并配置环境变量(图文步骤)
开发语言·windows·golang
San30.39 分钟前
ES6+ 新特性解析:让 JavaScript 开发更优雅高效
开发语言·javascript·es6
烤麻辣烫1 小时前
黑马程序员苍穹外卖(新手)DAY6
java·开发语言·学习·spring·intellij-idea
友友马1 小时前
『QT』窗口 (一)
开发语言·数据库·qt
APIshop2 小时前
Python 零基础写爬虫:一步步抓取商品详情(超细详解)
开发语言·爬虫·python
AI科技星2 小时前
为什么宇宙无限大?
开发语言·数据结构·经验分享·线性代数·算法
Appreciate(欣赏)2 小时前
JAVA使用poi类读取xlxs文件内容拼接成添加数据SQL
java·开发语言·sql
oioihoii3 小时前
性能提升11.4%!C++ Vector的reserve()方法让我大吃一惊
开发语言·c++
毕设源码-朱学姐3 小时前
【开题答辩全过程】以 基于JAVA的恒星酒店客房管理系统为例,包含答辩的问题和答案
java·开发语言
思密吗喽3 小时前
景区行李寄存管理系统
java·开发语言·spring boot·毕业设计·课程设计