惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

爱范儿
爱范儿
Microsoft Azure Blog
Microsoft Azure Blog
G
Google Developers Blog
宝玉的分享
宝玉的分享
V
V2EX
MongoDB | Blog
MongoDB | Blog
S
SegmentFault 最新的问题
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Microsoft Security Blog
Microsoft Security Blog
博客园 - 聂微东
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
IT之家
IT之家
Martin Fowler
Martin Fowler
大猫的无限游戏
大猫的无限游戏
Recent Announcements
Recent Announcements
人人都是产品经理
人人都是产品经理
博客园 - 司徒正美
美团技术团队
F
Fortinet All Blogs
N
Netflix TechBlog - Medium
Hugging Face - Blog
Hugging Face - Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
罗磊的独立博客
B
Blog RSS Feed

博客园 - 七月的火热

浅谈Excel 的VB编程 一组有用的操作Excel的函数 excel與vb.net的數據雙項操作,求高手幫忙! vb.net 操作excel - 七月的火热 - 博客园 VB.net,存EXCEL中的时间问题! VB.net调用Excel怎样设定列的列宽? 使用VB.NET编写控制excel的程序 ASP.NET中数据库数据导入Excel并打印 如何用VB.NET控制Excel單元格裡的內容? VB.net: 使用ODBC, ASP.net, VB.Net访问Excel文件 经改良后的vb.net导出excel代码 wsdl和soap的关系 Microsoft Solutions Framework Version 3 White Papers C#设计模式(12)-Decorator Pattern C#设计模式(11)-Composite Pattern C#设计模式(10)-Adapter Pattern C#设计模式(9)-Prototype Pattern C#设计模式(8)-Builder Pattern C#设计模式(7)-Singleton Pattern
如何用VB.NET控制Excel單元格裡的內容
七月的火热 · 2006-11-09 · via 博客园 - 七月的火热

Public  Sub  SetSheetStyles(ByVal  xlSheet  As  Excel.Worksheet,  _  
                                                                             ByVal  rowCount  As  Int32,  _  
                                                                             ByVal  colCount  As  Int32)  
               Dim  i,  intStart  As  Int32  
 
               With  xlSheet  
 
 
                       If  AllowHeaderColor  Then  .Range(.Cells(1,  1),  .Cells(1,  MasterColumnCount)).Interior.Color  =  GetHeaderBackColorRGB  
 
                       If  IsExistMasterD  Then  '主从表  
                               intStart  =  5  
 
                               .Range(.Cells(1,  1),  .Cells(1,  MasterColumnCount)).Font.Size  =  10  '标头字体大小  
                               .Range(.Cells(2,  1),  .Cells(2,  MasterColumnCount)).Font.Size  =  10  '主数据字体大小  
 
                               .Range(.Cells(1,  1),  .Cells(1,  MasterColumnCount)).Font.Bold  =  True      '标题字体加粗  
                               .Range(.Cells(2,  1),  .Cells(2,  MasterColumnCount)).Font.Italic  =  True      '主数据字体斜体  
 
                               .Range(.Cells(1,  1),  .Cells(1,  MasterColumnCount)).Borders.LineStyle  =  1    '粗边框(已取消)  
                               .Range(.Cells(2,  1),  .Cells(2,  MasterColumnCount)).Borders.LineStyle  =  1  '粗边框(已取消)  
 
                               If  AllowHeaderColor  Then  .Range(.Cells(4,  1),  .Cells(4,  colCount)).Interior.Color  =  GetHeaderBackColorRGB  
                               .Range(.Cells(4,  1),  .Cells(rowCount  +  4,  colCount)).Borders.LineStyle  =  1  '主数据边框样式  
 
                               .Range(.Cells(4,  1),  .Cells(4,  colCount)).Font.Bold  =  True      '标题字体加粗  
                               .Range(.Cells(4,  1),  .Cells(4,  colCount)).Font.Size  =  10  '数据项字体大小  
 
                               .Range(.Cells(5,  1),  .Cells(rowCount  +  4,  colCount)).Font.Size  =  9  '数据项字体大小  
 
                       Else  
                               intStart  =  2  
 
                               .Range(.Cells(1,  1),  .Cells(1,  colCount)).Font.Size  =  10  '标头字体大小  
                               .Range(.Cells(1,  1),  .Cells(1,  colCount)).Font.Bold  =  True      '标题字体加粗  
 
                               .Range(.Cells(1,  1),  .Cells(rowCount  +  1,  colCount)).Borders.LineStyle  =  1  '设表格边框样式  
                               .Range(.Cells(2,  1),  .Cells(rowCount  +  1,  colCount)).Font.Size  =  9  '数据项字体大小  
 
                       End  If  
 
                       If  exportSet.IsApply_PCR_ToExcelWord  AndAlso  exportSet.IsApplyExcel  Then  '允许使用颜色区分  
                               If  rowCount  >  2  AndAlso  exportSet.IsAlwaysQuestion_ApplyPCRToEW  Then  '先询问是否执行颜色区分  
                                       If  MessageBox.Show("数据转换到Excel文档已完成!是否现在就执行奇偶行颜色区分?这可能需要较长的时间。"  &  vbLf  &  "如果不再希望出现此提示,请转到  打印设置的高级选项卡。",  "总是询问",  MessageBoxButtons.YesNo,  MessageBoxIcon.Question,  MessageBoxDefaultButton.Button2)  =  DialogResult.No  Then  Return  
                               End  If  
                               If  rowCount  >  2  Then  Common.Common.OnInfo("开始用颜色来区分奇偶数据行,这可能需要较长的一段时间。请稍候...",  Common.InfoBase.InfoTypeEnum.Working)  
 
                               Dim  bolP  As  Boolean  =  (((rowCount  -  1)  Mod  2)  =  0)  '减去标头行Count  -  1  True=偶行  Even,False=奇行  Odd  
 
                               Dim  startD  As  Double  =  Microsoft.VisualBasic.Timer  
                               Dim  intEBC,  intOBC  As  Int32  
                               intEBC  =  GetEvenBackColorRGB  
                               intOBC  =  GetOddBackColorRGB  
 
                               Dim  intS  As  Int32  =  intStart  
                               rowCount  +=  intS  -  1  
                               For  i  =  intStart  To  rowCount  
                                       If  bolP  Then  '偶行  
                                               .Range(.Cells(i,  1),  .Cells(i,  colCount)).Interior.Color  =  intEBC  
                                       Else  '奇行  
                                               .Range(.Cells(i,  1),  .Cells(i,  colCount)).Interior.Color  =  intOBC  
                                       End  If  
 
                                       bolP  =  Not  bolP  
                               Next  i  
 
                               If  rowCount  >  2  Then  Common.Common.OnInfo("颜色区分奇偶数据行已完成!用时:"  &  (Microsoft.VisualBasic.Timer  -  startD).ToString  &  "  秒",  Common.InfoBase.InfoTypeEnum.Message)  
                       End  If  
 
               End  With  
 
               With  xlSheet.PageSetup  
                       If  MasterColumnCount  >  6  Then  
                               If  MasterColumnCount  >  12  Then  .PaperSize  =  Excel.XlPaperSize.xlPaperA3  '超过12列就用A3纸  
 
                               .Orientation  =  Excel.XlPageOrientation.xlLandscape  '横幅  
 
                       Else  
                               .Orientation  =  Excel.XlPageOrientation.xlPortrait  '竖幅A4纸  
                       End  If  
 
                       '  .TopMargin  =  1'不改变,因为有Header  
                       '.BottomMargin  =  1  
                       .LeftMargin  =  1  
                       .RightMargin  =  1  
 
                       .CenterHorizontally  =  True  '水平居中对齐  
                       '  .LeftHeaderPicture.Filename  =  Application.StartupPath  &  "\Resources\TRI-T  Icon.gif"  
                       .LeftHeader  =  "&""宋体,Bold""&13"  &  "TRI-T  Company  Limited"  '公司  
                       .CenterHeader  =  "&""宋体,Bold""&13"  &  TitleText    '标题"  
                       .LeftFooter  =  "&""宋体""&10制表人:"  &  PreparedBy  '制表人  
                       .CenterFooter  =  "&""宋体""&10制表日期:"  &  GetDatasheetDate  
                       .RightFooter  =  "&""宋体""&10第&P页  共&N页"  
               End  With  
 
       End  Sub  

posted on 2006-11-09 20:30  七月的火热  阅读(1009)  评论()    收藏  举报