zoukankan      html  css  js  c++  java
  • Get data style from Excel

    try
                {
                    Excel.Application app = new Excel.Application();
                    string excelFilePath = @"H:\22.xlsx";
                    Excel.Workbook book = app.Workbooks.Open(excelFilePath, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
                    StringBuilder sb = new StringBuilder();
                    Excel.Worksheet sheet = book.Sheets[1] as Worksheet;
                    for (int i = 0; i < 4; i++)
                    {
                        for (int k = 0; k < 4; k++)
                        {
                            try
                            {
                                Excel.Range range = (Excel.Range)sheet.Cells[i, k];
                                string fontName = range.Font.Name as string;
                                string fontSize = ((int)range.Font.Size).ToString();
    
                                string bgColor = (range.Interior.Color as object).ToString();
                                string height = ((float)range.Height).ToString();
                                string width = ((float)range.Width).ToString();
    
                                
                                string valign = GetVerticalAlignmentName((int)range.VerticalAlignment);
                                string halign = GetHorizontalAlignmentName((int)range.HorizontalAlignment);
    
                                string text = (range.Text as object).ToString();
    
                                string interior = range.Interior.Color as string;
                                
                                sb.AppendLine("Row:" + i.ToString() + " Col:" + k.ToString() + " Font:" + fontName);
                                sb.AppendLine("Row:" + i.ToString() + " Col:" + k.ToString() + " fontSize:" + fontSize);
    
                                sb.AppendLine("Row:" + i.ToString() + " Col:" + k.ToString() + " bgColor:" + bgColor);
                                sb.AppendLine("Row:" + i.ToString() + " Col:" + k.ToString() + " height:" + height);
                                sb.AppendLine("Row:" + i.ToString() + " Col:" + k.ToString() + " " + width);
                                sb.AppendLine("Row:" + i.ToString() + " Col:" + k.ToString() + " text:" + text);
    
                                sb.AppendLine("Row:" + i.ToString() + " Col:" + k.ToString() + " valign:" + valign);
    
                                sb.AppendLine("Row:" + i.ToString() + " Col:" + k.ToString() + " interior:" + interior);
    
    
                            }
                            catch(Exception ex)
                            {
                                //sb.AppendLine(ex.ToString());
     
                            }
                        }
                    }
                    this.richTextBox1.Text = sb.ToString();
    
                    book.Close(true, Type.Missing, Type.Missing);
                    book = null;
                    app.Quit();
                    app = null;
                    
                }
                catch
                {
     
                }
  • 相关阅读:
    夜半随笔
    VC6.0 工程转到VS2008一些问题
    没有找到MSVCR90.dll,因此这个应用程序未能启动,重新安装应用程序可解决
    开源中国
    保存桌面图标的次序吧
    2008下,错误:fatal error C1853
    生成成功,调试时出现错误导致中断Unhandled exception at 0x41cd7fb0 in webcam.exe: 0xC0000005: Access violatio
    opencv安装可能没注意的细节
    error PRJ0003 : 生成“cl.exe”时出错
    wince对话框添加菜单
  • 原文地址:https://www.cnblogs.com/TeyGao/p/2592909.html
Copyright © 2011-2022 走看看