基本信息
源码名称:C#处理Excel文档软件
源码大小:128.71M
文件格式:.rar
开发语言:C#
更新时间:2018-10-08
友情提示:(无需注册或充值,赞助后即可获取资源下载链接)
嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300
本次赞助数额为: 2 元×
微信扫码支付:2 元
×
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
源码介绍
自动处理Excel文档,删除空格,删除空白行(列),标红操作
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);
}
}
}
}
自动处理Excel文档,删除空格,删除空白行(列),标红操作
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);
}
}
}
}