W

로컬 텍스트 엑셀 파일 읽기/쓰기

· 2010-01-23 (토) 20:44:45 · 6792

익스플로우의 보안에 허용만 가능하면 자바스크립트 상에서도 읽기/쓰기가 가능하다.

 

우선 text파일 읽고 쓰는 예제이다.(C:\\book1.txt를 읽고 씀)

 

=====================================================================================================================

<html>
<head>
<title>file save/load</title>

 

<script type="text/javascript">

    var fso=new ActiveXObject("Scripting.FileSystemObject");
    var filename="C:\\book1.txt";
    function savefile() {
        if (!fso.FileExists(filename)) {
            fso.CreateTextFile(filename,true);
        }
        var f=fso.OpenTextFile(filename,2,true);
        f.Write(myarea.innerHTML);
        f.Close();
    }
   
    function loadfile() {
        if (!fso.FileExists(filename)) {
            fso.CreateTextFile(filename,true);
        }
        var f=fso.OpenTextFile(filename,1);
        r=f.ReadAll();
        f.Close();
        myarea.innerHTML=r;
    }
   
   
    //function window.onload() {
    //    loadfile(filename);
    //}
</script>


</head>
<body>
 <table>
  <tr>
   <td>
    <div id=myarea contenteditable=true style="width:320;height:240;border:solid 2 inset;overflow:scroll;background-color:silver;"></div>
    <br><input type=button value=load onclick=loadfile()><input type=button value=save onclick=savefile()>
   </td>
  </tr>
 </table>
</form>
</body>
</html>

 

======================================Excel 파일 열고 쓰기 =================================================

- 쓰기 -

<script type="text/javascript">

// Declare the variables
var Excel, Book;

// Create the Excel application object.
Excel = new ActiveXObject("Excel.Application");

// Make Excel visible.
Excel.Visible = true;

// Create a new work book.
Book = Excel.Workbooks.Add()

// Place some text in the first cell of the sheet.
Book.ActiveSheet.Cells(1,1).Value = "This is column A, row 1";

// Save the sheet.
Book.SaveAs("C:\\book1.xls");

// Close Excel with the Quit method on the Application object.
Excel.Application.Quit();
</script>

 

- 열기 -

function StartExcel() {
var oExcel;

var oWBook;
oExcel = new ActiveXObject("Excel.Application");

oExcel.Visible = true;

oExcel.workbooks.open("C:/test.xls");

oExcel.Quit();

oExcel = null;
}

 

간단한 파일 읽기의 경우 상당히 유용할 수 있겠다..

 
[이 게시물은 관리자님에 의해 2011-10-31 17:16:08 PHP & HTML에서 이동 됨]
|
댓글을 작성하시려면 로그인이 필요합니다.

프로그램

8,188건
+
제목 글쓴이 날짜 조회
12-08-29 조회 3,979
12-08-07 조회 3,645
12-08-03 조회 3,517
12-07-31 조회 3,625
12-07-30 조회 3,585
12-07-16 조회 3,796
12-07-15 조회 3,544
12-07-07 조회 3,496
12-07-06 조회 3,669
12-07-03 조회 3,655
12-06-29 조회 3,232
12-06-22 조회 3,603
12-06-17 조회 3,742
12-05-21 조회 3,787
12-05-02 조회 3,363
12-05-02 조회 4,158
12-05-02 조회 3,273
12-04-30 조회 3,445
12-04-30 조회 3,137
12-03-17 조회 3,989
12-03-10 조회 3,346
12-03-08 조회 3,817
12-03-03 조회 3,529
12-02-27 조회 4,948
12-02-17 조회 4,291
12-02-16 조회 4,506
12-02-03 조회 3,268
12-01-31 조회 3,057
12-01-24 조회 3,091
12-01-17 조회 3,841
12-01-05 조회 3,395
11-12-30 조회 3,041
11-12-23 조회 4,668
11-12-08 조회 3,388
11-12-07 조회 4,369
11-11-27 조회 3,791
11-11-25 조회 4,134
11-11-23 조회 3,540
11-11-22 조회 3,456
11-11-09 조회 3,189
11-10-23 조회 3,092
11-10-19 조회 3,067
11-10-08 조회 2,771
11-10-04 조회 2,780
11-10-04 조회 5,224
11-09-01 조회 4,282
11-08-13 조회 2,456
11-08-06 조회 3,149
11-07-11 조회 3,546
11-06-27 조회 2,922
11-06-21 조회 2,590
11-06-13 조회 2,374
11-06-07 조회 2,383
11-05-26 조회 2,375
11-04-20 조회 2,685
11-03-21 조회 2,772
11-03-18 조회 2,467
11-03-11 조회 2,510
11-02-07 조회 2,331
11-01-18 조회 2,644
11-01-12 조회 2,371
11-01-06 조회 2,485
10-12-10 조회 2,748
10-12-09 조회 2,437
10-12-08 조회 4,999
10-11-29 조회 2,562
10-11-28 조회 2,762
10-11-28 조회 2,604
10-11-19 조회 2,788
10-11-04 조회 2,681
10-10-21 조회 2,393
10-10-19 조회 3,342
10-10-12 조회 2,664
10-10-07 조회 2,496
10-09-30 조회 3,450
10-09-17 조회 3,847
10-09-17 조회 3,819
10-05-31 조회 3,481
09-12-31 조회 3,630
09-07-23 조회 4,948
08-09-16 조회 3,181
08-09-06 조회 2,912
08-09-04 조회 3,335
08-08-16 조회 4,389
08-08-15 조회 3,257
08-08-14 조회 4,465
08-08-12 조회 3,854
08-07-23 조회 2,766
08-07-10 조회 3,696
08-07-04 조회 2,918
08-06-27 조회 7,572
08-06-19 조회 4,860
08-05-27 조회 5,477
08-05-25 조회 5,308
08-05-23 조회 3,378
08-05-23 조회 4,512
08-05-21 조회 4,894
08-05-20 조회 4,020
08-05-20 조회 3,257
08-04-18 조회 4,288