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
                {
     
                }
  • 相关阅读:
    WebRequest 超时不起作用
    nutch导入ide nutch1.3
    nutch 设置抓取间隔策略
    c#: Error: Crossthread operation not valid
    mysql命令行基本操作
    Boost String Algorithms Library 函数详解三 (find)
    boost::timer 的替代方案
    windows驱动程序开发初探
    深入浅出Win32多线程程序设计之线程通信
    深入浅出Win32多线程设计之MFC的多线程(1)
  • 原文地址:https://www.cnblogs.com/TeyGao/p/2592909.html
Copyright © 2011-2022 走看看