欢迎来到传世资源网!
加载中...
正在加载,请耐心等待...
本站为收藏、学习站,如有侵权,请联系管理员删除!

C#处理Excel文档软件

介绍 评论 失效链接反馈

自动处理Excel文档,删除空格,删除空白行(列),标红操作
from clipboard
 CellRange ranges = sheet.Range[p "4"];
                string strValue = ranges.Value2.ToString();
                if (strValue.Contains('~'))//筛选,如果获取的字符串里有~就执行下面的循环
                {
                   strValue= strValue.Replace(")","");
                    strValue = strValue.Replace("(", "");
                    strValue = strValue.Replace(" ", "");//此处用了Replace方法,用括号后的字段代替前面的
                    string[] sArray = strValue.Split('~');                  
                    int X = sheet.Rows.Count();
                    CellRange rangeX = sheet.Range[p "5:" p X];//获取数据范围
                    ConditionalFormatWrapper formatx = rangeX.ConditionalFormats.AddCondition();//在所选范围里定义条件格式x
                    formatx.FormatType = ConditionalFormatType.CellValue;//条件格式的类型为各自值设置单元格的类型
                    formatx.FirstFormula = sArray[0];
                    formatx.SecondFormula = sArray[1];
                    formatx.Operator = ComparisonOperatorType.NotBetween;
                    formatx.IsBold = true;
                    formatx.BackColor = Color.Red;
                   //在集合sArray里的数据位界限 

                }
                else
                {
                    strValue = strValue.Replace("(","");
                    strValue = strValue.Replace(")", "");
                    strValue = strValue.Replace("-", "");
                    if (strValue.Contains('A'))
                    {

                        int X = sheet.Rows.Count();
                        CellRange rangeY = sheet.Range[p "5:" p X];
                        ConditionalFormatWrapper formatx = rangeY.ConditionalFormats.AddCondition();
                        formatx.FormatType = ConditionalFormatType.CellValue;
                        formatx.FirstFormula = "0";
                        
                        formatx.Operator = ComparisonOperatorType.NotEqual;
                        
                            formatx.IsBold = true;
                     
                    }
                    else
                    {
                        if (strValue.Length ==0)
                        {
                            int X = sheet.Rows.Count();
                            CellRange rangeZ = sheet.Range[p "5:" p X];
                            ConditionalFormatWrapper formatx = rangeZ.ConditionalFormats.AddCondition();
                            formatx.FormatType = ConditionalFormatType.CellValue;

                            formatx.FirstFormula = "0";

                            formatx.Operator = ComparisonOperatorType.NotEqual;
                            formatx.IsBold = true;
                        }
                        else

                        {
                            if (strValue.Length <= 15)
                            {
                                int X = sheet.Rows.Count();

                                CellRange rangeZ = sheet.Range[p "5:" p X];
                                ConditionalFormatWrapper formatx = rangeZ.ConditionalFormats.AddCondition();
                                formatx.FormatType = ConditionalFormatType.CellValue;

                                formatx.FirstFormula = strValue;

                                formatx.Operator = ComparisonOperatorType.NotEqual;
                                formatx.IsBold = true;
                                formatx.BackColor = Color.Red;
                            }
                            else
                            {
                                int X = sheet.Rows.Count();

                                CellRange rangeZ = sheet.Range[p "5:" p X];
                                ConditionalFormatWrapper formatx = rangeZ.ConditionalFormats.AddCondition();
                                formatx.FormatType = ConditionalFormatType.CellValue;

                                formatx.FirstFormula = "0";

                                formatx.Operator = ComparisonOperatorType.Equal;
                                formatx.IsBold = true;
                                formatx.BackColor = Color.Red;
                            }
                        }
                        
                    }
                }
            }
            string filename = Path.GetFileName(ExcelFilePath);
            try { workbook.SaveToFile(@"F:\" filename);
                System.Diagnostics.Process.Start(@"F:\" filename);
            }
            catch(Exception)
            {
                MessageBox.Show("你要保存的路径已被另一个同名文件占用!");
                MessageBox.Show("此文件将被保存在D盘根目录");
                workbook.SaveToFile(@"D:\" filename);
                System.Diagnostics.Process.Start(@"D:\" filename);
            }
        }
    }
}

下载声明:

本站资源均有第三方用户自行上传分享推荐,非本站自制,仅供玩家做交流学习之用!切勿用于商业用途!游戏作品版权归原作者享有,如有版权问题,请附带版权证明至邮件,本平台将应您的要求删除。
相关推荐:

评论

发表评论必须先登陆, 您可以 登陆 或者 注册新账号 !


在线咨询: 问题反馈
客服QQ:174666394

有问题请留言,看到后及时答复