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;

}

}

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

相关推荐
胡斌附体12 分钟前
qt socket编程正确重启tcpServer的姿势
开发语言·c++·qt·socket编程
木木黄木木23 分钟前
HTML5图片裁剪工具实现详解
前端·html·html5
白露与泡影35 分钟前
Java面试题及答案整理( 2025年 4 月最新版,持续更新)
java·开发语言
YueiL1 小时前
C++入门练习之 给出年分m和一年中的第n天,算出第n天是几月几号
开发语言·c++·算法
冷凝女子1 小时前
【QT】获取文件路径中的文件名,去掉后缀,然后提取文件名中的数字
开发语言·数据库·qt
我不想当小卡拉米1 小时前
C++:继承+菱形虚拟继承的一箭双雕
开发语言·jvm·c++
weixin_457885821 小时前
JavaScript智能对话机器人——企业知识库自动化
开发语言·javascript·自动化
孤独得猿1 小时前
Qt常用控件第一部分
服务器·开发语言·qt
慕斯策划一场流浪1 小时前
fastGPT—nextjs—mongoose—团队管理之团队列表api接口实现
开发语言·前端·javascript·fastgpt env文件配置·fastgpt团队列表接口实现·fastgpt团队切换api·fastgpt团队切换逻辑
勘察加熊人1 小时前
forms实现连连看
c#