使用C#在Excel中进行自动调整 [英] Row autofit in excel using C#

查看:204
本文介绍了使用C#在Excel中进行自动调整的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好



我试图自动扩展Excel工作表的行,但无法这样做。



请告诉我怎么办。



以下是我试过的代码。



我尝试过:



obj_Range = objxlApp.get_Range(objxlApp.Cells [(i + 2),1],objxlApp .Cells [(i + 2),dataTable.Columns.Count]);

obj_Range.Font.Bold = true;

obj_Range.Font.Size = 12;

obj_Range.Font.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.White);

obj_Range.Cells.Interior.Color = System.Drawing .ColorTranslator.ToOle(System.Drawing.Color.SteelBlue);

obj_Range.EntireRow.AutoFit();

obj_Range.Rows.AutoFit();

Hi all

I m trying to expand the rows of a excel sheet automatically, but unable to do so.

Please tell me how to do.

Below is the code i tried.

What I have tried:

obj_Range = objxlApp.get_Range(objxlApp.Cells[(i + 2), 1], objxlApp.Cells[(i + 2), dataTable.Columns.Count]);
obj_Range.Font.Bold = true;
obj_Range.Font.Size = 12;
obj_Range.Font.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.White);
obj_Range.Cells.Interior.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.SteelBlue);
obj_Range.EntireRow.AutoFit();
obj_Range.Rows.AutoFit();

推荐答案

最简单的方法是运行Excel,加载工作表并记录执行要复制的步骤的宏,停止录制,打开Visual Basic并查看录制的宏。



录制宏到自动调整列A:



列(A:A)。EntireColumn .AutoFit



您可能需要像obj_Range.Columns.EntireColumn.AutoFit
The easiest way to to it is run Excel, load a sheet and record a macro executing the steps you want to replicate, stop recording, open Visual Basic and look at the recorded Macro.

Recorded macro to autofit column A:

Columns("A:A").EntireColumn.AutoFit

You may need something like obj_Range.Columns.EntireColumn.AutoFit

这篇关于使用C#在Excel中进行自动调整的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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