Created
June 21, 2016 03:19
-
-
Save engalar/8563d6bdb0d0ad0e5681e29967c0cc0c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.IO; | |
using Microsoft.Office.Interop.Excel; | |
using Microsoft.VisualStudio.TestTools.UnitTesting; | |
namespace CSharpUnitTestProject1 | |
{ | |
[TestClass] | |
public class DataProcessTest | |
{ | |
[TestMethod] | |
public void TestMethod1() | |
{ | |
var directoryInfo = new DirectoryInfo("C:\\DeviceData_VS\\logs\\Specifications\\新建文件夹"); | |
foreach (var enumerateDirectory in directoryInfo.EnumerateDirectories()) | |
{ | |
// Console.Out.WriteLine(enumerateDirectory.FullName); | |
foreach (var info in enumerateDirectory.EnumerateDirectories()) | |
{ | |
// Console.Out.WriteLine(info.FullName); | |
foreach (var enumerateFile in info.EnumerateFiles()) | |
{ | |
// Console.Out.WriteLine(enumerateFile.FullName); | |
Tranlation(enumerateFile); | |
} | |
} | |
} | |
} | |
public void Tranlation(FileInfo fileInfo) | |
{ | |
Application excelApplication = new Application(); | |
try | |
{ | |
excelApplication.Visible = true; | |
var workbook = excelApplication.Workbooks.Open(fileInfo.FullName, ReadOnly: true); | |
foreach (var sheet in workbook.Worksheets) | |
{ | |
var worksheet = sheet as Worksheet; | |
foreach (var range in worksheet.UsedRange.Columns) | |
{ | |
var range1 = (Range)range; | |
if (range1.Column < 4) | |
{ | |
continue; | |
} | |
var add = (FormatCondition)range1.FormatConditions.Add(XlFormatConditionType.xlCellValue, | |
XlFormatConditionOperator.xlBetween, "=" + range1.Offset[2, 0].Address[1, 1].Split(Convert.ToChar(":"))[0], "=" + range1.Offset[3, 0].Address[1, 1].Split(Convert.ToChar(":"))[0]); | |
add.Interior.Color = -16383844;//红 | |
} | |
worksheet.SaveAs(fileInfo.DirectoryName + "\\" + worksheet.Name + ".xls", FileFormat: XlFileFormat.xlExcel8); | |
} | |
} | |
finally | |
{ | |
excelApplication.Quit(); | |
} | |
} | |
} | |
} | |
// | |
//Sub Macro1() | |
//' | |
//' Macro1 Macro | |
//' | |
// | |
//' | |
// Selection.Copy | |
// Range("B1:J4").Select | |
// Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _ | |
// SkipBlanks:=False, Transpose:=False | |
// Application.CutCopyMode = False | |
// Range("A1").Select | |
// Selection.Copy | |
// Rows("1:4").Select | |
// Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _ | |
// SkipBlanks:=False, Transpose:=False | |
// Application.CutCopyMode = False | |
// Rows("1:4").Select | |
// Selection.FormatConditions.Delete | |
// With Selection | |
// .HorizontalAlignment = xlLeft | |
// .VerticalAlignment = xlCenter | |
// .WrapText = False | |
// .Orientation = 0 | |
// .AddIndent = False | |
// .IndentLevel = 0 | |
// .ShrinkToFit = False | |
// .ReadingOrder = xlContext | |
// .MergeCells = False | |
// End With | |
// Range("D5").Select | |
// ActiveWindow.FreezePanes = True | |
// Rows("4:4").Select | |
// Selection.AutoFilter | |
//End Sub |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment