使用c#将格式从一行复制到另一行 [英] Copy format from one row to another using c#

查看:28
本文介绍了使用c#将格式从一行复制到另一行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题与提出的问题非常相似 这里.但是给出的答案建议将格式与数据一起复制.我有一个使用 SSIS 生成的 excel 表 (.xlsx).现在我已经在第一行设置了格式,我想将其复制到工作表中已经填写的所有行.我怎样才能使用 C# 做到这一点?我正在使用 Excel 互操作.

This question is quite similar to the one asked here. But the answer given suggests copying the format along with the data. I have a excel sheet (.xlsx) that I generate using SSIS. Now I have set the formatting in first row, which I want to copy to all the rows that are already filled in the worksheet. How can I do that using C#? I am using Excel interop.

推荐答案

你可以使用PasteSpecialxlPasteFormats.

Excel.Range R1 = (Excel.Range)oSheet.Cells[11, 11];
R1.Copy(Type.Missing);

Excel.Range R2 = (Excel.Range)oSheet.Cells[15, 15];
R2.PasteSpecial(Excel.XlPasteType.xlPasteFormats,
    Excel.XlPasteSpecialOperation.xlPasteSpecialOperationNone, false, false);

这篇关于使用c#将格式从一行复制到另一行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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