일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | |||||
3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 |
- Eclipse
- resource
- netsh
- lsof
- Windows 10
- GIT
- bash
- import
- tomcat
- 단축키
- web.xml
- Mac
- profile
- find
- VirtualBox
- port
- xargs
- JavaScript
- Windows
- grep
- ssh
- plugin
- context
- Source
- maVen
- 줄바꿈 문자
- IntelliJ
- vscode
- 네트워크
- Quartz
- Today
- Total
develog
excel open protected password in jacob 본문
JACOB - Java COM Bridge
http://sourceforge.net/projects/jacob-project/
-------------------------------------------------------------------------------
import java.io.File;
import com.jacob.activeX.ActiveXComponent;
import com.jacob.com.Dispatch;
import com.jacob.com.Variant;
public class TestMain {
public static void main(String[] args) throws Exception {
System.out.println("START");
System.out.println("------------------------------");
TestMain main = new TestMain();
main.setPassword(
"excel/source.xlsx",
"excel/source.xls",
"123"
);
System.out.println("------------------------------");
System.out.println("END");
}
public void setPassword(String sourceFileNm, String outputFileNm, String password) throws Exception {
String sourceFile = new File(sourceFileNm).getCanonicalPath();
String outputFile = new File(outputFileNm).getCanonicalPath();
ActiveXComponent comp = null;
try {
comp = new ActiveXComponent("Excel.Application");
comp.setProperty("Visible", new Variant(false));
Dispatch workbooks = comp.getProperty("Workbooks").toDispatch();
Dispatch workbook = Dispatch.invoke(workbooks, "Open", Dispatch.Method, new Object[] {sourceFile, new Variant(false), new Variant(true) }, new int[1]).toDispatch();
Dispatch.call(workbook, "SaveAs", new Variant(outputFile), new Variant("1"), new Variant(password));
} finally {
if (comp != null) {
comp.invoke("Quit", new Variant[]{});
}
}
}
}
'Dev > Java' 카테고리의 다른 글
java mail (0) | 2013.06.12 |
---|---|
UserException (0) | 2013.06.11 |
getAbsolutePath, getCanonicalPath (0) | 2013.06.08 |
Jacob (0) | 2013.06.08 |
@Autowired 사용시 셋팅 (0) | 2013.05.30 |