在Excel文件格式的条件 [英] Conditional format on Excel file
问题描述
这是可能做到Excel的一些条件格式JXL或Apache POI或别的什么文件? API的Java例如像宏VBA?
'濑身材的COULEUR倒差
对于i = 3翅片第1步
范围(C&放大器;ⅰ)。选择
Selection.FormatConditions.Delete
Selection.FormatConditions.Add类型:= xlCellValue,运营商:= xlNotEqual,_
一级方程式:== B与&一世
Selection.FormatConditions(1).Interior.ColorIndex = 6
因此,在目标语言,这些都是你需要的Excel对象:
- 在像变量创建
Excel.Application
的实例 oXlApp - 使用
Excel.Application
对象,以打开目标工作簿:- 致电打开在 oXlApp 工作簿的集合中的文件名作为参数传递给Open方法 的方法
- 使用 oxlApp 对象的
选择
属性返回一个Excel范围
对象 -
修改
选择
或范围
如下:- 执行一个删除的条件格式方式在范围 财产
-
执行的添加的条件格式命令财产的范围
- 传递这些参数的添加方式:
- 类型:= xlEx pression
- 一级方程式:== $ B2<> $ C2
- 将第一格式的这个属性条件的设置细胞色的:
- 条件格式(1).Interior.ColorIndex = 36
- 传递这些参数的添加方式:
- 调用*的保存的*在您的工作簿方法
- 清理调用关闭的工作簿和退出的 oXlApp 方式和最后,释放内存!的
在 Excel VBA中我们会做这样的事:
activesheet.usedrange.select
Selection.FormatConditions.Delete
Selection.FormatConditions.Add类型:= xlEx pression,一级方程式:== $ B2<> $ C2
Selection.FormatConditions(1).Interior.ColorIndex = 36
这将首先选择使用的单元,然后添加一个条件格式为列B和C
另外,看到这一个
<一href=\"http://stackoverflow.com/questions/15612316/jacob-calling-vb-function-in-excel-file-without-invoking-open-statement/15618533#15618533\">StackOverFlow:雅各操作的Excel / Java的
和看 JXL指南
Is that possible to do some conditional format on Excel file with JXL or Apache POI or something else? API java Like Macro VBA for example?
' Mise en forme couleur pour différence
For i = 3 To fin Step 1
Range("C" & i).Select
Selection.FormatConditions.Delete
Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlNotEqual, _
Formula1:="=B" & i
Selection.FormatConditions(1).Interior.ColorIndex = 6
so, in your target language, these are the Excel Objects you need:
- Create an instance of
Excel.Application
in a variable like oXlApp - use the
Excel.Application
object to open your target workbook:- Call the Open method of the oXlApp Workbooks collection passing in the filename as an argument to the Open method
- use the
Selection
property of the oxlApp object to return an ExcelRange
object modify the
Selection
orRange
as below:- Execute a Delete method on the FormatConditions property of the Range
Execute an Add command on the FormatConditions property of the Range
- pass in these arguments to the Add method:
- Type:=xlExpression
- Formula1:="=$B2<>$C2"
- set this property of the first Format Condition to set the cells color:
- FormatConditions(1).Interior.ColorIndex = 36
- pass in these arguments to the Add method:
'
- Call the *Save*method on your workbook
- Clean up calling the Close method on the Workbook then Quit on the oXlApp and finally, RELEASE MEMORY!
in Excel VBA we would do something like this:
activesheet.usedrange.select
Selection.FormatConditions.Delete
Selection.FormatConditions.Add Type:=xlExpression, Formula1:="=$B2<>$C2"
Selection.FormatConditions(1).Interior.ColorIndex = 36
this will first select the used cells, then add a conditional formatting for cols b and c
Also, see this one StackOverFlow: Manipulate Excel from Jacob/Java
and look at the JXL Guide
这篇关于在Excel文件格式的条件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!