W

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

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

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

 

우선 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-03-19 조회 3,581
12-03-16 조회 4,112
12-03-14 조회 3,999
12-03-13 조회 3,608
12-03-13 조회 4,457
12-03-12 조회 5,551
12-03-12 조회 1만
12-03-08 조회 6,107
12-03-06 조회 1.1만
12-03-06 조회 3,824
12-03-06 조회 6,325
12-03-02 조회 5,120
12-02-29 조회 3,668
12-02-27 조회 4,180
12-02-22 조회 3,718
12-02-20 조회 3,702
12-02-20 조회 6,775
12-02-01 조회 3,305
12-01-30 조회 8,847
12-01-29 조회 3,330
12-01-24 조회 3,664
12-01-21 조회 3,314
12-01-10 조회 3,771
11-12-26 조회 3,685
11-12-23 조회 5,105
11-12-23 조회 4,754
11-12-23 조회 4,356
11-12-23 조회 8,063
11-12-22 조회 3,800
11-12-17 조회 3,843
11-12-12 조회 3,258
11-12-08 조회 7,784
11-12-08 조회 3,610
11-12-07 조회 3,873
11-12-06 조회 5,637
11-12-02 조회 3,574
11-12-01 조회 3,196
11-11-30 조회 6,990
11-11-26 조회 3,947
11-11-24 조회 4,699
11-11-22 조회 3,087
11-11-22 조회 6,704
11-11-18 조회 5,129
11-11-16 조회 3,503
11-11-14 조회 3,532
11-11-12 조회 4,008
11-11-08 조회 3,330
11-11-06 조회 1만
11-11-06 조회 3,917
11-11-03 조회 5,603
11-11-02 조회 5,883
11-11-01 조회 9,397
11-10-19 조회 2,897
11-10-17 조회 2,683
11-10-10 조회 2,661
11-10-07 조회 3,417
11-10-06 조회 4,008
11-10-06 조회 2,567
11-10-02 조회 3,319
11-09-08 조회 4,335
11-09-08 조회 2,707
11-09-07 조회 2,681
11-09-02 조회 2,775
11-09-01 조회 3,721
11-08-28 조회 3,611
11-08-23 조회 3,435
11-08-22 조회 2,855
11-08-22 조회 2,446
11-08-13 조회 2,505
11-08-05 조회 2,946
11-08-03 조회 4,149
11-07-03 조회 2,628
11-06-15 조회 3,272
11-06-15 조회 3,106
11-05-15 조회 2,914
11-05-11 조회 5,640
11-04-12 조회 3,061
11-01-27 조회 3,884
11-01-26 조회 2,681
11-01-26 조회 4,516
11-01-18 조회 2,727
10-11-23 조회 2,960
10-10-24 조회 4,771
10-09-15 조회 4,463
10-09-07 조회 3,449
10-08-27 조회 4,129
10-08-20 조회 7,010
10-07-30 조회 5,693
10-06-30 조회 2,957
10-06-11 조회 4,713
10-06-11 조회 3,402
10-05-15 조회 4,243
10-05-10 조회 2,928
10-03-19 조회 5,474
10-03-05 조회 5,235
10-02-17 조회 5,675
09-11-21 조회 6,989
09-11-09 조회 4,050
09-11-04 조회 6,778
09-10-26 조회 3,908