如何更改工作表中的行号位置。 [英] How change row number position in the sheet.

查看:90
本文介绍了如何更改工作表中的行号位置。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好!


我想更改我的excel文件,并在我的数据之前删除所有现有的空行。


示例:我之前有 






我希望之后: 



我不知道如何在Open XML 2.5中快速修改我的文件。


但是我找到了Microsoft.Office.Interop.Excel的解决方案: 

 //创建一个新的工作簿。 
//打开现有的Excel文件。
工作簿wb =新工作簿(@"d:\test\book1.xls");

//参考
//工作簿的工作表创建一个Worksheets对象。
WorksheetCollection sheet = wb.Worksheets;

//从WorksheetCollection获取第一张工作表
工作表sheet = sheets [0];

//从工作表中删除空行
sheet.Cells.DeleteBlankRows();

但我不能使用excel服务器端的应用程序......


请帮帮我)





解决方案

嗨谢尔盖,


根据我使用Open XML Productivity工具的测试,它会更改每个单元格的CellReference。


还有Row.Remove()方法可以删除行。


我建议您使用Open XML Productivity工具比较两个文件并生成代码,然后检查详细代码。


问候


Starain


Hi all!

I want change my excel file and remove from them all existing empty rows before my data.

Example: I have before 

I want to have after: 

I don't know how I can fast modify my files in Open XML 2.5.

But I found solution for Microsoft.Office.Interop.Excel: 

//Create a new Workbook.
//Open an existing excel file.
Workbook wb = new Workbook(@"d:\test\book1.xls");

//Create a Worksheets object with reference to
//the sheets of the Workbook.
WorksheetCollection sheets = wb.Worksheets;

//Get first Worksheet from WorksheetCollection
Worksheet sheet = sheets[0];

//Delete the Blank Rows from the worksheet
sheet.Cells.DeleteBlankRows();

But I must't use excel app on server side...

Help me please)


解决方案

Hi Sergey,

Based on my test with Open XML Productivity tool, it changes the CellReference for each cells.

Also there is Row.Remove() method that could remove row.

I suggest that you could use Open XML Productivity tool to compare two files and generate the code, then check the detail code.

Regards

Starain


这篇关于如何更改工作表中的行号位置。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆