W

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

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

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

 

우선 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,187건
+
제목 글쓴이 날짜 조회
08-11-25 조회 3,773
08-11-25 조회 2,966
08-11-25 조회 4,541
08-11-25 조회 4,414
08-11-21 조회 4,395
08-11-21 조회 5,324
08-11-20 조회 3,951
08-11-20 조회 3,763
08-11-19 조회 4,032
08-11-19 조회 4,271
08-11-18 조회 4,052
08-11-15 조회 2,931
08-11-14 조회 3,236
08-11-14 조회 2,904
08-11-14 조회 3,295
08-11-13 조회 3,919
08-11-12 조회 1만
08-11-07 조회 4,625
08-11-07 조회 5,618
08-11-03 조회 3,383
08-11-01 조회 5,089
08-11-01 조회 3,045
08-10-30 조회 2,753
08-10-30 조회 3,683
08-10-30 조회 2,779
08-10-30 조회 3,016
08-10-30 조회 2,884
08-10-29 조회 3,958
08-10-29 조회 2,940
08-10-29 조회 2,472
08-10-20 조회 2,610
08-10-18 조회 4,555
08-10-16 조회 3,612
08-10-16 조회 3,414
08-10-14 조회 2,615
08-10-11 조회 3,918
08-10-11 조회 2,507
08-10-09 조회 2,604
08-10-09 조회 2,758
08-10-09 조회 4,230
08-10-08 조회 3,926
08-10-02 조회 3,866
08-10-02 조회 2,612
08-10-02 조회 2,762
08-09-29 조회 4,694
08-09-29 조회 4,322
08-09-26 조회 5,636
08-09-26 조회 3,604
08-09-26 조회 3,675
08-09-26 조회 2,816
08-09-26 조회 3,855
08-09-26 조회 3,599
08-09-26 조회 4,359
08-09-22 조회 3,923
08-09-22 조회 3,106
08-09-22 조회 4,070
08-09-22 조회 3,030
08-09-22 조회 2,682
08-09-21 조회 3,675
08-09-20 조회 4,250
08-09-20 조회 5,521
08-09-20 조회 4,626
08-09-20 조회 2,943
08-09-20 조회 3,345
08-09-20 조회 3,706
08-09-20 조회 3,087
08-09-20 조회 3,270
08-09-20 조회 4,255
08-09-20 조회 3,753
08-09-20 조회 3,332
08-09-19 조회 5,731
08-09-19 조회 4,508
08-09-19 조회 2,819
08-09-18 조회 5,172
08-09-18 조회 4,255
08-09-18 조회 3,625
08-09-18 조회 2,823
08-09-18 조회 3,741
08-09-18 조회 3,544
08-09-17 조회 3,402
08-09-16 조회 3,345
08-09-10 조회 2,560
08-09-09 조회 3,362
08-09-06 조회 4,248
08-09-06 조회 2,810
08-09-06 조회 3,182
08-09-06 조회 2,839
08-09-06 조회 3,071
08-09-06 조회 2,954
08-09-06 조회 2,929
08-09-05 조회 3,930
08-09-05 조회 3,759
08-09-05 조회 3,578
08-09-05 조회 2,799
08-09-05 조회 3,823
08-09-05 조회 5,785
08-09-05 조회 4,246
08-09-05 조회 3,143
08-09-05 조회 3,287
08-09-05 조회 4,713