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
                {
     
                }
  • 相关阅读:
    Echarts入门踩坑记录
    作业帮前端面经
    猿辅导前端面经
    昆仑万维前端面经
    顺丰科技前端面经
    云从科技前端面经
    亿联网络前端面经
    寒武纪前端面经
    纽约州交通事故数据可视化
    Vue中Object和Array数据变化侦测原理
  • 原文地址:https://www.cnblogs.com/TeyGao/p/2592909.html
Copyright © 2011-2022 走看看